Skip to content

Fix names and default values of Agent Config settings. #1065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The following packages need to be installed:
```
git clone https://github.com/open-telemetry/opentelemetry-collector.git
cd opentelemetry-collector
git checkout v0.114.0
git checkout v0.124.0
cd cmd/mdatagen
go install
```
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/nginxossreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ status:
beta: [metrics]
distributions: [contrib]
codeowners:
active: [aphralG, dhurley, craigell, sean-breen, Rashmiti, CVanF5]
active: [ aphralG, dhurley, craigell, sean-breen, CVanF5 ]

resource_attributes:
instance.id:
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/nginxplusreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ status:
beta: [metrics]
distributions: [contrib]
codeowners:
active: [aphralG, dhurley, craigell, sean-breen, Rashmiti, CVanF5]
active: [ aphralG, dhurley, craigell, sean-breen, CVanF5 ]

resource_attributes:
instance.id:
Expand Down
9 changes: 6 additions & 3 deletions internal/collector/otel_collector_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (
)

const (
maxTimeToWaitForShutdown = 30 * time.Second
filePermission = 0o600
maxTimeToWaitForShutdown = 30 * time.Second
defaultCollectionInterval = 1 * time.Minute
filePermission = 0o600
// To conform to the rfc3164 spec the timestamp in the logs need to be formatted correctly.
// Here are some examples of what the timestamp conversions look like.
// Notice how if the day begins with a zero that the zero is replaced with an empty space.
Expand Down Expand Up @@ -405,6 +406,7 @@ func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigC
Listen: nginxConfigContext.PlusAPI.Listen,
Location: nginxConfigContext.PlusAPI.Location,
},
CollectionInterval: defaultCollectionInterval,
},
)

Expand Down Expand Up @@ -438,7 +440,8 @@ func (oc *Collector) addNginxOssReceiver(nginxConfigContext *model.NginxConfigCo
Listen: nginxConfigContext.StubStatus.Listen,
Location: nginxConfigContext.StubStatus.Location,
},
AccessLogs: toConfigAccessLog(nginxConfigContext.AccessLogs),
AccessLogs: toConfigAccessLog(nginxConfigContext.AccessLogs),
CollectionInterval: defaultCollectionInterval,
},
)

Expand Down
2 changes: 2 additions & 0 deletions internal/collector/otel_collector_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func TestCollector_ProcessNginxConfigUpdateTopic(t *testing.T) {
Listen: "",
Location: "",
},
CollectionInterval: defaultCollectionInterval,
},
},
},
Expand Down Expand Up @@ -229,6 +230,7 @@ func TestCollector_ProcessNginxConfigUpdateTopic(t *testing.T) {
LogFormat: "$$remote_addr - $$remote_user [$$time_local] \\\"$$request\\\"",
},
},
CollectionInterval: defaultCollectionInterval,
},
},
},
Expand Down
8 changes: 6 additions & 2 deletions internal/collector/otelcol.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ receivers:
url: "{{- .StubStatus.URL -}}"
listen: "{{- .StubStatus.Listen -}}"
location: "{{- .StubStatus.Location -}}"
collection_interval: 10s
{{- if .CollectionInterval }}
collection_interval: {{ .CollectionInterval }}
{{- end }}
{{- if gt (len .AccessLogs) 0 }}
access_logs:
{{- range .AccessLogs }}
Expand All @@ -96,7 +98,9 @@ receivers:
url: "{{- .PlusAPI.URL -}}"
listen: "{{- .PlusAPI.Listen -}}"
location: "{{- .PlusAPI.Location -}}"
collection_interval: 10s
{{- if .CollectionInterval }}
collection_interval: {{ .CollectionInterval }}
{{- end }}
{{- end }}
{{- range $index, $tcplogReceiver := .Receivers.TcplogReceivers }}
tcplog/{{$index}}:
Expand Down
1 change: 1 addition & 0 deletions internal/collector/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestTemplateWrite(t *testing.T) {
Location: "",
Listen: "",
},
CollectionInterval: 30 * time.Second,
AccessLogs: []config.AccessLog{
{
LogFormat: accessLogFormat,
Expand Down
10 changes: 9 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"testing"
"time"

"github.com/nginx/agent/v3/pkg/config"

"github.com/nginx/agent/v3/test/helpers"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -882,11 +884,13 @@ func createConfig() *Config {
FilePath: "/var/log/nginx/access-custom.conf",
},
},
CollectionInterval: 30 * time.Second,
},
},
NginxPlusReceivers: []NginxPlusReceiver{
{
InstanceID: "cd7b8911-c2c5-4daf-b311-dbead151d939",
InstanceID: "cd7b8911-c2c5-4daf-b311-dbead151d939",
CollectionInterval: 30 * time.Second,
},
},
HostMetrics: &HostMetrics{
Expand Down Expand Up @@ -966,5 +970,9 @@ func createConfig() *Config {
"label2": "new-value",
"label3": 123,
},
Features: []string{
config.FeatureCertificates, config.FeatureFileWatcher, config.FeatureMetrics,
config.FeatureAPIAction, config.FeatureLogsNap,
},
}
}
2 changes: 1 addition & 1 deletion internal/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (
DefBackoffInitialInterval = 500 * time.Millisecond
DefBackoffRandomizationFactor = 0.5 // the value is 0 <= and < 1
DefBackoffMultiplier = 1.5
DefBackoffMaxInterval = 5 * time.Second
DefBackoffMaxInterval = 10 * time.Minute
DefBackoffMaxElapsedTime = 30 * time.Second

// Watcher defaults
Expand Down
4 changes: 2 additions & 2 deletions internal/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
CollectorExportersKey = pre(CollectorRootKey) + "exporters"
CollectorAttributeProcessorKey = pre(CollectorProcessorsKey) + "attribute"
CollectorDebugExporterKey = pre(CollectorExportersKey) + "debug"
CollectorPrometheusExporterKey = pre(CollectorExportersKey) + "prometheus_exporter"
CollectorPrometheusExporterKey = pre(CollectorExportersKey) + "prometheus"
CollectorPrometheusExporterServerHostKey = pre(CollectorPrometheusExporterKey) + "server_host"
CollectorPrometheusExporterServerPortKey = pre(CollectorPrometheusExporterKey) + "server_port"
CollectorPrometheusExporterTLSKey = pre(CollectorPrometheusExporterKey) + "tls"
Expand All @@ -56,7 +56,7 @@ var (
CollectorPrometheusExporterTLSCaKey = pre(CollectorPrometheusExporterTLSKey) + "ca"
CollectorPrometheusExporterTLSSkipVerifyKey = pre(CollectorPrometheusExporterTLSKey) + "skip_verify"
CollectorPrometheusExporterTLSServerNameKey = pre(CollectorPrometheusExporterTLSKey) + "server_name"
CollectorOtlpExportersKey = pre(CollectorExportersKey) + "otlp_exporters"
CollectorOtlpExportersKey = pre(CollectorExportersKey) + "otlp"
CollectorProcessorsKey = pre(CollectorRootKey) + "processors"
CollectorBatchProcessorKey = pre(CollectorProcessorsKey) + "batch"
CollectorBatchProcessorSendBatchSizeKey = pre(CollectorBatchProcessorKey) + "send_batch_size"
Expand Down
20 changes: 14 additions & 6 deletions internal/config/testdata/nginx-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ labels:
label2: new-value
label3: 123

features:
- certificates
- file-watcher
- metrics
- api-action
- logs-nap

data_plane_config:
nginx:
reload_monitoring_period: 30s
Expand Down Expand Up @@ -53,7 +60,6 @@ command:
server:
host: "127.0.0.1"
port: 8888
type: grpc
auth:
token: "1234"
tokenpath: "path/to/my_token"
Expand All @@ -67,7 +73,7 @@ command:
collector:
config_path: "/etc/nginx-agent/nginx-agent-otelcol.yaml"
receivers:
otlp_receivers:
otlp:
- server:
host: "127.0.0.1"
port: 4317
Expand All @@ -80,13 +86,15 @@ collector:
ca: /tmp/ca.pem
cert: /tmp/cert.pem
key: /tmp/key.pem
nginx_receivers:
nginx:
- instance_id: cd7b8911-c2c5-4daf-b311-dbead151d938
access_logs:
- file_path: "/var/log/nginx/access-custom.conf"
log_format: "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\""
nginx_plus_receivers:
collection_interval: 30s
nginx_plus:
- instance_id: cd7b8911-c2c5-4daf-b311-dbead151d939
collection_interval: 30s
host_metrics:
collection_interval: 10s
initial_delay: 2s
Expand All @@ -103,7 +111,7 @@ collector:
action: "insert"
value: "value"
exporters:
otlp_exporters:
otlp:
- server:
host: "127.0.0.1"
port: 5643
Expand All @@ -114,7 +122,7 @@ collector:
cert: /path/to/server-cert.pem
key: /path/to/server-key.pem
ca: /path/to/server-cert.pem
prometheus_exporter:
prometheus:
server:
host: "127.0.0.1"
port: 1235
Expand Down
32 changes: 17 additions & 15 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ type (
}

Exporters struct {
Debug *DebugExporter `yaml:"debug" mapstructure:"debug"`
PrometheusExporter *PrometheusExporter `yaml:"prometheus_exporter" mapstructure:"prometheus_exporter"`
OtlpExporters []OtlpExporter `yaml:"otlp_exporters" mapstructure:"otlp_exporters"`
Debug *DebugExporter `yaml:"debug" mapstructure:"debug"`
PrometheusExporter *PrometheusExporter `yaml:"prometheus" mapstructure:"prometheus"`
OtlpExporters []OtlpExporter `yaml:"otlp" mapstructure:"otlp"`
}

OtlpExporter struct {
Expand Down Expand Up @@ -181,12 +181,12 @@ type (

// OTel Collector Receiver configuration.
Receivers struct {
ContainerMetrics *ContainerMetricsReceiver `yaml:"container_metrics" mapstructure:"container_metrics"`
HostMetrics *HostMetrics `yaml:"host_metrics" mapstructure:"host_metrics"`
OtlpReceivers []OtlpReceiver `yaml:"otlp_receivers" mapstructure:"otlp_receivers"`
NginxReceivers []NginxReceiver `yaml:"nginx_receivers" mapstructure:"nginx_receivers"`
NginxPlusReceivers []NginxPlusReceiver `yaml:"nginx_plus_receivers" mapstructure:"nginx_plus_receivers"`
TcplogReceivers []TcplogReceiver `yaml:"tcplog_receivers" mapstructure:"tcplog_receivers"`
ContainerMetrics *ContainerMetricsReceiver `yaml:"container_metrics" mapstructure:"container_metrics"`
HostMetrics *HostMetrics `yaml:"host_metrics" mapstructure:"host_metrics"`
OtlpReceivers []OtlpReceiver `yaml:"otlp" mapstructure:"otlp"`
NginxReceivers []NginxReceiver `yaml:"nginx" mapstructure:"nginx"`
NginxPlusReceivers []NginxPlusReceiver `yaml:"nginx_plus" mapstructure:"nginx_plus"`
TcplogReceivers []TcplogReceiver `yaml:"tcplog" mapstructure:"tcplog"`
}

OtlpReceiver struct {
Expand All @@ -209,9 +209,10 @@ type (
}

NginxReceiver struct {
InstanceID string `yaml:"instance_id" mapstructure:"instance_id"`
StubStatus APIDetails `yaml:"api_details" mapstructure:"api_details"`
AccessLogs []AccessLog `yaml:"access_logs" mapstructure:"access_logs"`
InstanceID string `yaml:"instance_id" mapstructure:"instance_id"`
StubStatus APIDetails `yaml:"api_details" mapstructure:"api_details"`
AccessLogs []AccessLog `yaml:"access_logs" mapstructure:"access_logs"`
CollectionInterval time.Duration `yaml:"collection_interval" mapstructure:"collection_interval"`
}

APIDetails struct {
Expand All @@ -226,12 +227,13 @@ type (
}

NginxPlusReceiver struct {
InstanceID string `yaml:"instance_id" mapstructure:"instance_id"`
PlusAPI APIDetails `yaml:"api_details" mapstructure:"api_details"`
InstanceID string `yaml:"instance_id" mapstructure:"instance_id"`
PlusAPI APIDetails `yaml:"api_details" mapstructure:"api_details"`
CollectionInterval time.Duration `yaml:"collection_interval" mapstructure:"collection_interval"`
}

ContainerMetricsReceiver struct {
CollectionInterval time.Duration `yaml:"-" mapstructure:"collection_interval"`
CollectionInterval time.Duration `yaml:"collection_interval" mapstructure:"collection_interval"`
}

HostMetrics struct {
Expand Down
4 changes: 2 additions & 2 deletions test/config/agent/nginx-agent-otel-load.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ allowed_directories:

collector:
receivers:
otlp_receivers:
otlp:
- server:
host: "127.0.0.1"
port: 4317
processors:
batch: {}
exporters:
otlp_exporters:
otlp:
- server:
host: "127.0.0.1"
port: 5643
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ receivers:
url: "http://localhost:80/status"
listen: ""
location: ""
collection_interval: 10s
collection_interval: 30s
access_logs:
- log_format: "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\"\"$upstream_cache_status\""
file_path: "/var/log/nginx/access-custom.conf"
Expand Down
14 changes: 6 additions & 8 deletions test/mock/collector/nginx-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,28 @@ allowed_directories:
- /var/run/nginx

client:
timeout: 10s
http:
timeout: 10s

collector:
log:
level: DEBUG
receivers:
container_metrics:
collection_interval: 10s
collection_interval: 1m0s
host_metrics:
collection_interval: 1m0s
initial_delay: 1s
scrapers:
cpu: {}
memory: {}
disk: {}
network: {}
filesystem: {}
otlp_receivers:
otlp:
- server:
host: "127.0.0.1"
port: 4317
type: 0
auth:
Token: secret-receiver-token
token: secret-receiver-token
tls:
server_name: test-local-server
ca: /tmp/ca.pem
Expand All @@ -62,7 +60,7 @@ collector:
batch: {}
exporters:
debug:
otlp_exporters:
otlp:
- server:
host: "otel-collector"
port: 4317
Expand Down