diff --git a/receiver/prometheusreceiver/go.mod b/receiver/prometheusreceiver/go.mod index aeb41f37830c4..a0e15d71c7619 100644 --- a/receiver/prometheusreceiver/go.mod +++ b/receiver/prometheusreceiver/go.mod @@ -21,7 +21,6 @@ require ( github.com/prometheus/exporter-toolkit v0.14.0 github.com/prometheus/prometheus v0.304.3-0.20250703114031-419d436a447a github.com/stretchr/testify v1.11.1 - github.com/testcontainers/testcontainers-go v0.38.0 go.opentelemetry.io/collector/component v1.41.1-0.20250911155607-37a3ace6274c go.opentelemetry.io/collector/component/componentstatus v0.135.1-0.20250911155607-37a3ace6274c go.opentelemetry.io/collector/component/componenttest v0.135.1-0.20250911155607-37a3ace6274c @@ -225,6 +224,7 @@ require ( github.com/spf13/cobra v1.10.1 // indirect github.com/spf13/pflag v1.0.9 // indirect github.com/stackitcloud/stackit-sdk-go/core v0.17.2 // indirect + github.com/testcontainers/testcontainers-go v0.38.0 // indirect github.com/tidwall/gjson v1.10.2 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect diff --git a/receiver/prometheusreceiver/kong_integration_test.go b/receiver/prometheusreceiver/kong_integration_test.go index 065f4340bcc2b..3cae7c81a219c 100644 --- a/receiver/prometheusreceiver/kong_integration_test.go +++ b/receiver/prometheusreceiver/kong_integration_test.go @@ -6,12 +6,15 @@ package prometheusreceiver // Copyright The OpenTelemetry Authors import ( + "net" + "net/http" + "net/http/httptest" + "os" "path/filepath" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/testcontainers/testcontainers-go" - "github.com/testcontainers/testcontainers-go/wait" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap/confmaptest" @@ -22,18 +25,11 @@ import ( const kongPort = "18001" func TestKongIntegration(t *testing.T) { + mockServer := setupMockKongServer(t) + defer mockServer.Close() + scraperinttest.NewIntegrationTest( NewFactory(), - scraperinttest.WithContainerRequest( - testcontainers.ContainerRequest{ - FromDockerfile: testcontainers.FromDockerfile{ - Context: filepath.Join("testdata", "kong"), - Dockerfile: "Dockerfile", - }, - ExposedPorts: []string{kongPort + ":" + "8001"}, - WaitingFor: wait.ForLog(".*connected to events broker.*").AsRegexp(), - }), - scraperinttest.AllowHardcodedHostPort(), scraperinttest.WithCustomConfig( func(t *testing.T, cfg component.Config, _ *scraperinttest.ContainerInfo) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "kong", "config.yaml")) @@ -58,3 +54,20 @@ func TestKongIntegration(t *testing.T) { ), ).Run(t) } + +func setupMockKongServer(t *testing.T) *httptest.Server { + fullPath := filepath.Join("testdata", "kong", "scraped-kong-data.txt") + data, err := os.ReadFile(fullPath) + require.NoError(t, err) + + server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + _, err = w.Write(data) + assert.NoError(t, err) + })) + + l, _ := net.Listen("tcp", "localhost:"+kongPort) + server.Listener = l + server.Start() + + return server +} diff --git a/receiver/prometheusreceiver/testdata/kong/Dockerfile b/receiver/prometheusreceiver/testdata/kong/Dockerfile deleted file mode 100644 index de255ceb4cf30..0000000000000 --- a/receiver/prometheusreceiver/testdata/kong/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM kong/kong-gateway:3.11.0.3 - -COPY kong.yml /kong/declarative/kong.yml - -ENV KONG_DATABASE=off -ENV KONG_DECLARATIVE_CONFIG=/kong/declarative/kong.yml -ENV KONG_PROXY_ACCESS_LOG=/dev/stdout -ENV KONG_ADMIN_ACCESS_LOG=/dev/stdout -ENV KONG_PROXY_ERROR_LOG=/dev/stderr -ENV KONG_ADMIN_ERROR_LOG=/dev/stderr -ENV KONG_ADMIN_LISTEN=0.0.0.0:8001 -ENV KONG_ADMIN_GUI_URL=http://localhost:8002 diff --git a/receiver/prometheusreceiver/testdata/kong/config.yaml b/receiver/prometheusreceiver/testdata/kong/config.yaml index 156a4324eb167..8019d6fbfcd40 100644 --- a/receiver/prometheusreceiver/testdata/kong/config.yaml +++ b/receiver/prometheusreceiver/testdata/kong/config.yaml @@ -4,4 +4,4 @@ config: scrape_interval: 1s static_configs: - targets: - - "localhost:18001" \ No newline at end of file + - "localhost:18001" diff --git a/receiver/prometheusreceiver/testdata/kong/kong.yml b/receiver/prometheusreceiver/testdata/kong/kong.yml deleted file mode 100644 index acf32e68ace8b..0000000000000 --- a/receiver/prometheusreceiver/testdata/kong/kong.yml +++ /dev/null @@ -1,13 +0,0 @@ -_format_version: "3.0" -_transform: true - -services: - - host: localhost - name: example_service - port: 80 - protocol: http - routes: - - name: example_route - paths: - - /mock - strip_path: true \ No newline at end of file diff --git a/receiver/prometheusreceiver/testdata/kong/scraped-kong-data.txt b/receiver/prometheusreceiver/testdata/kong/scraped-kong-data.txt new file mode 100644 index 0000000000000..4ada574b6f66f --- /dev/null +++ b/receiver/prometheusreceiver/testdata/kong/scraped-kong-data.txt @@ -0,0 +1,92 @@ +# HELP kong_datastore_reachable Datastore reachable from Kong, 0 is unreachable +# TYPE kong_datastore_reachable gauge +kong_datastore_reachable 1 +# HELP kong_memory_lua_shared_dict_bytes Allocated slabs in bytes in a shared_dict +# TYPE kong_memory_lua_shared_dict_bytes gauge +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong",kong_subsystem="http"} 45056 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_cluster_events",kong_subsystem="http"} 40960 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_consumers_db_cache",kong_subsystem="http"} 794624 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_consumers_db_cache_miss",kong_subsystem="http"} 86016 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_core_db_cache",kong_subsystem="http"} 798720 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_core_db_cache_miss",kong_subsystem="http"} 86016 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_counters",kong_subsystem="http"} 16384 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_db_cache",kong_subsystem="http"} 811008 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_db_cache_miss",kong_subsystem="http"} 86016 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_debug_session",kong_subsystem="http"} 16384 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_healthchecks",kong_subsystem="http"} 40960 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_keyring",kong_subsystem="http"} 40960 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_locks",kong_subsystem="http"} 61440 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_profiling_state",kong_subsystem="http"} 20480 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_rate_limiting_counters",kong_subsystem="http"} 86016 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_reports_consumers",kong_subsystem="http"} 73728 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_reports_routes",kong_subsystem="http"} 16384 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_reports_services",kong_subsystem="http"} 16384 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_reports_workspaces",kong_subsystem="http"} 16384 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_secrets",kong_subsystem="http"} 40960 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_vaults_hcv",kong_subsystem="http"} 16384 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_vitals",kong_subsystem="http"} 16384 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_vitals_counters",kong_subsystem="http"} 315392 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_vitals_lists",kong_subsystem="http"} 16384 +kong_memory_lua_shared_dict_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="prometheus_metrics",kong_subsystem="http"} 40960 +# HELP kong_memory_lua_shared_dict_total_bytes Total capacity in bytes of a shared_dict +# TYPE kong_memory_lua_shared_dict_total_bytes gauge +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong",kong_subsystem="http"} 5242880 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_cluster_events",kong_subsystem="http"} 5242880 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_consumers_db_cache",kong_subsystem="http"} 134217728 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_consumers_db_cache_miss",kong_subsystem="http"} 12582912 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_core_db_cache",kong_subsystem="http"} 134217728 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_core_db_cache_miss",kong_subsystem="http"} 12582912 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_counters",kong_subsystem="http"} 1048576 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_db_cache",kong_subsystem="http"} 134217728 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_db_cache_miss",kong_subsystem="http"} 12582912 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_debug_session",kong_subsystem="http"} 1048576 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_healthchecks",kong_subsystem="http"} 5242880 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_keyring",kong_subsystem="http"} 5242880 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_locks",kong_subsystem="http"} 8388608 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_profiling_state",kong_subsystem="http"} 1572864 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_rate_limiting_counters",kong_subsystem="http"} 12582912 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_reports_consumers",kong_subsystem="http"} 10485760 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_reports_routes",kong_subsystem="http"} 1048576 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_reports_services",kong_subsystem="http"} 1048576 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_reports_workspaces",kong_subsystem="http"} 1048576 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_secrets",kong_subsystem="http"} 5242880 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_vaults_hcv",kong_subsystem="http"} 1048576 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_vitals",kong_subsystem="http"} 1048576 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_vitals_counters",kong_subsystem="http"} 52428800 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="kong_vitals_lists",kong_subsystem="http"} 1048576 +kong_memory_lua_shared_dict_total_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",shared_dict="prometheus_metrics",kong_subsystem="http"} 5242880 +# HELP kong_memory_workers_lua_vms_bytes Allocated bytes in worker Lua VM +# TYPE kong_memory_workers_lua_vms_bytes gauge +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2630",kong_subsystem="http"} 80994484 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2631",kong_subsystem="http"} 80493077 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2632",kong_subsystem="http"} 80493077 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2633",kong_subsystem="http"} 80494145 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2634",kong_subsystem="http"} 80495686 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2635",kong_subsystem="http"} 80497569 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2636",kong_subsystem="http"} 80529461 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2637",kong_subsystem="http"} 80495317 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2638",kong_subsystem="http"} 80493681 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2639",kong_subsystem="http"} 80493685 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2640",kong_subsystem="http"} 80493685 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2641",kong_subsystem="http"} 80493685 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2642",kong_subsystem="http"} 80493685 +kong_memory_workers_lua_vms_bytes{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",pid="2643",kong_subsystem="http"} 80496709 +# HELP kong_nginx_connections_total Number of connections by subsystem +# TYPE kong_nginx_connections_total gauge +kong_nginx_connections_total{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",subsystem="http",state="accepted"} 19 +kong_nginx_connections_total{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",subsystem="http",state="active"} 15 +kong_nginx_connections_total{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",subsystem="http",state="handled"} 19 +kong_nginx_connections_total{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",subsystem="http",state="reading"} 0 +kong_nginx_connections_total{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",subsystem="http",state="total"} 19 +kong_nginx_connections_total{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",subsystem="http",state="waiting"} 0 +kong_nginx_connections_total{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",subsystem="http",state="writing"} 15 +# HELP kong_nginx_requests_total Number of requests total +# TYPE kong_nginx_requests_total gauge +kong_nginx_requests_total{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",subsystem="http"} 19 +# HELP kong_nginx_timers Number of nginx timers +# TYPE kong_nginx_timers gauge +kong_nginx_timers{state="pending"} 2 +kong_nginx_timers{state="running"} 257 +# HELP kong_node_info Kong Node metadata information +# TYPE kong_node_info gauge +kong_node_info{node_id="b420701d-16f8-4eca-ae4b-0877e29de2f9",version="3.11.0.3"} 1