Skip to content

Move NGINX discovery to OTel receiver #5689

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

Merged
merged 15 commits into from
Dec 12, 2024
Merged
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 .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ jobs:
id: get-matrix
run: |
includes=""
for service in "apache" "mongodb" "kafkametrics" "jmx/cassandra"; do
for service in "apache" "jmx/cassandra" "kafkametrics" "mongodb" "nginx"; do
for arch in "amd64" "arm64"; do
if [ "$service" = "mongodb" ]; then
# tests for mongo "6.0" and "7.0" are flaky, skipping for now
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### 💡 Enhancements 💡

- (Splunk) Automatic Discovery:
- Switch bundled NGINX discovery to create [OpenTelemetry NGINX receiver](https://docs.splunk.com/observability/en/gdi/opentelemetry/components/nginx-receiver.html#nginx-receiver) instead of the Smart Agent NGINX monitor ([#5689](https://github.com/signalfx/splunk-otel-collector/pull/5689))

### 🚩Deprecations 🚩

- (Splunk) Deprecate the collectd/genericjmx monitor. Please use the [jmxreceiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/jmxreceiver) instead. ([#5539](https://github.com/signalfx/splunk-otel-collector/pull/5539))
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ integration-test-jmx/cassandra-discovery:
integration-test-apache-discovery:
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_apachewebserver -v -timeout 5m -count 1 ./...

.PHONY: integration-test-nginx-discovery
integration-test-nginx-discovery:
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_nginx -v -timeout 5m -count 1 ./...

.PHONY: smartagent-integration-test
smartagent-integration-test:
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=smartagent_integration -v -timeout 5m -count 1 ./...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ splunk.discovery:
receivers:
mysql:
enabled: true
nginx:
enabled: true
postgresql:
enabled: true
smartagent/collectd/mysql:
enabled: false
smartagent/collectd/nginx:
enabled: true
smartagent/postgresql:
enabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#####################################################################################
# This file is generated by the Splunk Distribution of the OpenTelemetry Collector. #
# #
# It reflects the default configuration bundled in the Collector executable for use #
# in discovery mode (--discovery) and is provided for reference or customization. #
# Please note that any changes made to this file will need to be reconciled during #
# upgrades of the Collector. #
#####################################################################################
# nginx:
# enabled: true
# rule:
# docker_observer: type == "container" and any([name, image, command], {# matches "(?i)nginx"}) and not (command matches "splunk.discovery")
# host_observer: type == "hostport" and command matches "(?i)nginx" and not (command matches "splunk.discovery")
# k8s_observer: type == "port" and pod.name matches "(?i)nginx"
# config:
# default:
# endpoint: '`(port in [443] ? "https://" : "http://")``endpoint`/nginx_status}}'
# status:
# metrics:
# - status: successful
# strict: nginx.connections_accepted
# message: nginx receiver is working!
# statements:
# - status: failed
# regexp: "Failed to fetch nginx stats"
# message: Failed to retrieve metrics from NGINX stub_status endpoint.
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ services:
build: ./mysql
ports:
- "3306:3306"
# Nginx image for collectd-nginx test:
nginx:
image: quay.io/splunko11ytest/nginx:latest
profiles:
- integration
- integration-test-nginx-discovery
- smartagent
build: ./nginx
ports:
Expand Down
2 changes: 1 addition & 1 deletion internal/confmapprovider/discovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ The following components have bundled discovery configurations in the last Splun
I. Receivers
* `mongodb` ([Linux and Windows](./bundle/bundle.d/receivers/mongodb.discovery.yaml))
* `mysql` ([Linux and Windows](./bundle/bundle.d/receivers/mysql.discovery.yaml))
* `nginx` ([Linux and Windows](./bundle/bundle.d/receivers/nginx.discovery.yaml))
* `oracledb` ([Linux and Windows](./bundle/bundle.d/receivers/oracledb.discovery.yaml))
* `postgresql` ([Linux and Windows](./bundle/bundle.d/receivers/postgresql.discovery.yaml))
* `redis` ([Linux and Windows](./bundle/bundle.d/receivers/redis.discovery.yaml))
* `smartagent` with `collectd/mysql` monitor type ([Linux](./bundle/bundle.d/receivers/smartagent-collectd-mysql.discovery.yaml))
* `smartagent` with `collectd/nginx` monitor type ([Linux](./bundle/bundle.d/receivers/smartagent-collectd-nginx.discovery.yaml))
* `smartagent` with `postgresql` monitor type ([Linux and Windows](./bundle/bundle.d/receivers/smartagent-postgresql.discovery.yaml))
* `sqlserver` ([Linux And Windows](./bundle/bundle.d/receivers/sqlserver.discovery.yaml))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,21 @@
# Do not edit manually! #
# All changes must be made to associated .tmpl file before running 'make bundle.d'. #
#####################################################################################
smartagent/collectd/nginx:
nginx:
enabled: true
rule:
docker_observer: type == "container" and any([name, image, command], {# matches "(?i)nginx"}) and not (command matches "splunk.discovery")
host_observer: type == "hostport" and command matches "(?i)nginx" and not (command matches "splunk.discovery")
k8s_observer: type == "port" and pod.name matches "(?i)nginx"
config:
default:
type: collectd/nginx
url: '`(port in [443, 8443] ? "https" : "http") + "://{{.Host}}:{{.Port}}/nginx_status"`'
timeout: 5000
isolatedCollectd: true
endpoint: '`(port in [443] ? "https://" : "http://")``endpoint`/nginx_status}}'
status:
metrics:
- status: successful
strict: connections.accepted
message: smartagent/collectd/nginx receiver is working!
strict: nginx.connections_accepted
message: nginx receiver is working!
statements:
- status: failed
regexp: "nginx plugin: curl_easy_perform failed: Operation timed out after"
message: The container is not serving http connections.
- status: failed
regexp: "read-function of plugin .* failed"
message: The integration is unable to read metrics from this endpoint.
regexp: "Failed to fetch nginx stats"
message: Failed to retrieve metrics from NGINX stub_status endpoint.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{ receiver "nginx" }}:
enabled: true
rule:
docker_observer: type == "container" and any([name, image, command], {# matches "(?i)nginx"}) and not (command matches "splunk.discovery")
host_observer: type == "hostport" and command matches "(?i)nginx" and not (command matches "splunk.discovery")
k8s_observer: type == "port" and pod.name matches "(?i)nginx"
config:
default:
endpoint: '`(port in [443] ? "https://" : "http://")``endpoint`/nginx_status}}'
status:
metrics:
- status: successful
strict: nginx.connections_accepted
message: nginx receiver is working!
statements:
- status: failed
regexp: "Failed to fetch nginx stats"
message: Failed to retrieve metrics from NGINX stub_status endpoint.

This file was deleted.

4 changes: 2 additions & 2 deletions internal/confmapprovider/discovery/bundle/bundle_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/mongodb.discovery.yaml.tmpl
//go:generate discoverybundler --render --template bundle.d/receivers/mysql.discovery.yaml.tmpl
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/mysql.discovery.yaml.tmpl
//go:generate discoverybundler --render --template bundle.d/receivers/nginx.discovery.yaml.tmpl
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/nginx.discovery.yaml.tmpl
//go:generate discoverybundler --render --template bundle.d/receivers/oracledb.discovery.yaml.tmpl
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/oracledb.discovery.yaml.tmpl
//go:generate discoverybundler --render --template bundle.d/receivers/postgresql.discovery.yaml.tmpl
Expand All @@ -43,8 +45,6 @@
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/redis.discovery.yaml.tmpl
//go:generate discoverybundler --render --template bundle.d/receivers/smartagent-collectd-mysql.discovery.yaml.tmpl
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/smartagent-collectd-mysql.discovery.yaml.tmpl
//go:generate discoverybundler --render --template bundle.d/receivers/smartagent-collectd-nginx.discovery.yaml.tmpl
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/smartagent-collectd-nginx.discovery.yaml.tmpl
//go:generate discoverybundler --render --template bundle.d/receivers/smartagent-postgresql.discovery.yaml.tmpl
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/smartagent-postgresql.discovery.yaml.tmpl
//go:generate discoverybundler --render --template bundle.d/receivers/sqlserver.discovery.yaml.tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func TestBundleDir(t *testing.T) {
"bundle.d/receivers/kafkametrics.discovery.yaml",
"bundle.d/receivers/mongodb.discovery.yaml",
"bundle.d/receivers/mysql.discovery.yaml",
"bundle.d/receivers/nginx.discovery.yaml",
"bundle.d/receivers/oracledb.discovery.yaml",
"bundle.d/receivers/postgresql.discovery.yaml",
"bundle.d/receivers/rabbitmq.discovery.yaml",
"bundle.d/receivers/redis.discovery.yaml",
"bundle.d/receivers/smartagent-collectd-mysql.discovery.yaml",
"bundle.d/receivers/smartagent-collectd-nginx.discovery.yaml",
"bundle.d/receivers/smartagent-postgresql.discovery.yaml",
"bundle.d/receivers/sqlserver.discovery.yaml",
}, receivers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import (
//go:embed bundle.d/receivers/kafkametrics.discovery.yaml
//go:embed bundle.d/receivers/mongodb.discovery.yaml
//go:embed bundle.d/receivers/mysql.discovery.yaml
//go:embed bundle.d/receivers/nginx.discovery.yaml
//go:embed bundle.d/receivers/oracledb.discovery.yaml
//go:embed bundle.d/receivers/postgresql.discovery.yaml
//go:embed bundle.d/receivers/rabbitmq.discovery.yaml
//go:embed bundle.d/receivers/redis.discovery.yaml
//go:embed bundle.d/receivers/smartagent-collectd-mysql.discovery.yaml
//go:embed bundle.d/receivers/smartagent-collectd-nginx.discovery.yaml
//go:embed bundle.d/receivers/smartagent-postgresql.discovery.yaml
//go:embed bundle.d/receivers/sqlserver.discovery.yaml
var BundledFS embed.FS
2 changes: 1 addition & 1 deletion internal/confmapprovider/discovery/bundle/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ var (
"kafkametrics",
"mongodb",
"mysql",
"nginx",
"oracledb",
"postgresql",
"rabbitmq",
"redis",
"smartagent-collectd-mysql",
"smartagent-collectd-nginx",
"smartagent-postgresql",
"sqlserver",
}
Expand Down
51 changes: 51 additions & 0 deletions tests/receivers/nginx/nginx_discovery_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright Splunk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build discovery_integration_nginx

package tests

import (
"path/filepath"
"runtime"
"testing"

"github.com/stretchr/testify/require"

"github.com/signalfx/splunk-otel-collector/tests/internal/discoverytest"
)

func TestIntegrationNGINXAutoDiscovery(t *testing.T) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
t.Skip("Integration tests are only run on linux architecture: https://github.com/signalfx/splunk-otel-collector/blob/main/.github/workflows/integration-test.yml#L35")
}

tests := map[string]struct {
configFileName string
logMessageToAssert string
}{
"Successful Discovery test": {
configFileName: "docker_observer_nginx_config.yaml",
logMessageToAssert: `nginx receiver is working!`,
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
otelConfigPath, err := filepath.Abs(filepath.Join(".", "testdata", test.configFileName))
require.NoError(t, err)
discoverytest.Run(t, "nginx", otelConfigPath, test.logMessageToAssert)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
extensions:
docker_observer:
use_host_bindings: true
basicauth:
client_auth:
username: some_user
password: some_password

receivers:
discovery:
embed_receiver_config: true
receivers:
nginx:
config:
endpoint: '`(port in [443] ? "https://" : "http://")``endpoint`/nginx_status}}'
auth:
authenticator: basicauth
collection_interval: 1s
rule: type == "container" and any([name, image, command], {# matches "(?i)nginx"}) and not (command matches "splunk.discovery")
status:
metrics:
- status: successful
strict: nginx.connections_accepted
message: nginx receiver is working!
statements:
- status: failed
regexp: "Failed to fetch nginx stats"
message: Failed to retrieve metrics from NGINX stub_status endpoint.
watch_observers:
- docker_observer

exporters:
debug:
verbosity: detailed
otlp:
endpoint: "${OTLP_ENDPOINT}"
tls:
insecure: true

service:
telemetry:
logs:
level: info
extensions:
- docker_observer
- basicauth
pipelines:
logs:
receivers: [discovery]
exporters: [otlp, debug]
Loading