From 3e429bac92bcc05dab9f69fc3dbd40a87176abfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Tudur=C3=AD?= Date: Mon, 5 Feb 2024 14:50:07 +0100 Subject: [PATCH] add initial integration tests for exporters (#6269) * add integration test for redis exporter --- Makefile | 4 +- integration-tests/common/metrics_assert.go | 2 - integration-tests/docker-compose.yaml | 6 +- integration-tests/main.go | 2 +- integration-tests/tests/redis/config.river | 25 +++ .../tests/redis/redis_metrics_test.go | 32 ++++ integration-tests/tests/unix/config.river | 23 +++ .../tests/unix/unix_metrics_test.go | 164 ++++++++++++++++++ integration-tests/utils.go | 14 +- 9 files changed, 259 insertions(+), 13 deletions(-) create mode 100644 integration-tests/tests/redis/config.river create mode 100644 integration-tests/tests/redis/redis_metrics_test.go create mode 100644 integration-tests/tests/unix/config.river create mode 100644 integration-tests/tests/unix/unix_metrics_test.go diff --git a/Makefile b/Makefile index 7bdd7fdee77f..f08f0f9d89a8 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ ## ## test Run tests ## lint Lint code -## integration-tests Run integration tests +## integration-test Run integration tests ## ## Targets for building binaries: ## @@ -167,7 +167,7 @@ test-packages: docker pull $(BUILD_IMAGE) go test -tags=packaging ./packaging -.PHONY: integration-tests +.PHONY: integration-test integration-test: cd integration-tests && $(GO_ENV) go run . diff --git a/integration-tests/common/metrics_assert.go b/integration-tests/common/metrics_assert.go index 5704f9e49ff0..5797a74271a0 100644 --- a/integration-tests/common/metrics_assert.go +++ b/integration-tests/common/metrics_assert.go @@ -98,8 +98,6 @@ func AssertMetricData(t *testing.T, query, expectedMetric string, testName strin if assert.NotEmpty(c, metricResponse.Data.Result) { assert.Equal(c, metricResponse.Data.Result[0].Metric.Name, expectedMetric) assert.Equal(c, metricResponse.Data.Result[0].Metric.TestName, testName) - fmt.Println(metricResponse.Data.Result[0]) - fmt.Println(metricResponse.Data.Result[0].Value) assert.NotEmpty(c, metricResponse.Data.Result[0].Value.Value) assert.Nil(c, metricResponse.Data.Result[0].Histogram) } diff --git a/integration-tests/docker-compose.yaml b/integration-tests/docker-compose.yaml index a94a05db21d9..eb5650f75f7f 100644 --- a/integration-tests/docker-compose.yaml +++ b/integration-tests/docker-compose.yaml @@ -29,4 +29,8 @@ services: dockerfile: ./integration-tests/configs/prom-gen/Dockerfile context: .. ports: - - "9001:9001" \ No newline at end of file + - "9001:9001" + redis: + image: redis:6.0.9-alpine + ports: + - "6379:6379" \ No newline at end of file diff --git a/integration-tests/main.go b/integration-tests/main.go index 29009742efae..7b48d21576d3 100644 --- a/integration-tests/main.go +++ b/integration-tests/main.go @@ -43,7 +43,7 @@ func runIntegrationTests(cmd *cobra.Command, args []string) { specificTest = "./tests/" + specificTest } logChan = make(chan TestLog, 1) - runSingleTest(specificTest) + runSingleTest(specificTest, 12345) } else { testDirs, err := filepath.Glob("./tests/*") if err != nil { diff --git a/integration-tests/tests/redis/config.river b/integration-tests/tests/redis/config.river new file mode 100644 index 000000000000..ae333681cf4e --- /dev/null +++ b/integration-tests/tests/redis/config.river @@ -0,0 +1,25 @@ +prometheus.exporter.redis "redis_metrics" { + redis_addr = "localhost:6379" +} + +prometheus.scrape "redis_metrics" { + targets = prometheus.exporter.redis.redis_metrics.targets + forward_to = [prometheus.remote_write.redis_metrics.receiver] + scrape_interval = "1s" + scrape_timeout = "500ms" +} + +prometheus.remote_write "redis_metrics" { + endpoint { + url = "http://localhost:9009/api/v1/push" + metadata_config { + send_interval = "1s" + } + queue_config { + max_samples_per_send = 100 + } + } + external_labels = { + test_name = "redis_metrics", + } +} diff --git a/integration-tests/tests/redis/redis_metrics_test.go b/integration-tests/tests/redis/redis_metrics_test.go new file mode 100644 index 000000000000..b21c35c0ef0f --- /dev/null +++ b/integration-tests/tests/redis/redis_metrics_test.go @@ -0,0 +1,32 @@ +//go:build !windows + +package main + +import ( + "testing" + + "github.com/grafana/agent/integration-tests/common" +) + +func TestRedisMetrics(t *testing.T) { + var redisMetrics = []string{ + "redis_up", + "redis_memory_used_bytes", + "redis_blocked_clients", + "redis_commands_duration_seconds_total", + "redis_commands_total", + "redis_connected_clients", + "redis_connected_slaves", + "redis_db_keys", + "redis_db_keys_expiring", + "redis_evicted_keys_total", + "redis_keyspace_hits_total", + "redis_keyspace_misses_total", + "redis_memory_max_bytes", + "redis_memory_used_bytes", + "redis_memory_used_rss_bytes", + "redis_up", + } + // TODO(marctc): Report list of failed metrics instead of one by one. + common.MimirMetricsTest(t, redisMetrics, []string{}, "redis_metrics") +} diff --git a/integration-tests/tests/unix/config.river b/integration-tests/tests/unix/config.river new file mode 100644 index 000000000000..cb8ce5cdbf83 --- /dev/null +++ b/integration-tests/tests/unix/config.river @@ -0,0 +1,23 @@ +prometheus.exporter.unix "node_exporter" { } + +prometheus.scrape "demo" { + targets = prometheus.exporter.unix.node_exporter.targets + forward_to = [prometheus.remote_write.node_exporter.receiver] + scrape_interval = "1s" + scrape_timeout = "500ms" +} + +prometheus.remote_write "node_exporter" { + endpoint { + url = "http://localhost:9009/api/v1/push" + metadata_config { + send_interval = "1s" + } + queue_config { + max_samples_per_send = 100 + } + } + external_labels = { + test_name = "unix_metrics", + } +} \ No newline at end of file diff --git a/integration-tests/tests/unix/unix_metrics_test.go b/integration-tests/tests/unix/unix_metrics_test.go new file mode 100644 index 000000000000..15c4dae42603 --- /dev/null +++ b/integration-tests/tests/unix/unix_metrics_test.go @@ -0,0 +1,164 @@ +//go:build !windows + +package main + +import ( + "testing" + + "github.com/grafana/agent/integration-tests/common" +) + +func TestUnixMetrics(t *testing.T) { + var unixMetrics = []string{ + "node_arp_entries", + "node_boot_time_seconds", + "node_context_switches_total", + "node_cpu_seconds_total", + "node_disk_io_time_seconds_total", + "node_disk_io_time_weighted_seconds_total", + "node_disk_read_bytes_total", + "node_disk_read_time_seconds_total", + "node_disk_reads_completed_total", + "node_disk_write_time_seconds_total", + "node_disk_writes_completed_total", + "node_disk_written_bytes_total", + "node_filefd_allocated", + "node_filefd_maximum", + "node_filesystem_avail_bytes", + "node_filesystem_device_error", + "node_filesystem_files", + "node_filesystem_files_free", + "node_filesystem_readonly", + "node_filesystem_size_bytes", + "node_intr_total", + "node_load1", + "node_load15", + "node_load5", + "node_memory_Active_anon_bytes", + "node_memory_Active_bytes", + "node_memory_Active_file_bytes", + "node_memory_AnonHugePages_bytes", + "node_memory_AnonPages_bytes", + "node_memory_Bounce_bytes", + "node_memory_Buffers_bytes", + "node_memory_Cached_bytes", + "node_memory_CommitLimit_bytes", + "node_memory_Committed_AS_bytes", + "node_memory_DirectMap1G_bytes", + "node_memory_DirectMap2M_bytes", + "node_memory_DirectMap4k_bytes", + "node_memory_Dirty_bytes", + "node_memory_HugePages_Free", + "node_memory_HugePages_Rsvd", + "node_memory_HugePages_Surp", + "node_memory_HugePages_Total", + "node_memory_Hugepagesize_bytes", + "node_memory_Inactive_anon_bytes", + "node_memory_Inactive_bytes", + "node_memory_Inactive_file_bytes", + "node_memory_Mapped_bytes", + "node_memory_MemAvailable_bytes", + "node_memory_MemFree_bytes", + "node_memory_MemTotal_bytes", + "node_memory_SReclaimable_bytes", + "node_memory_SUnreclaim_bytes", + "node_memory_ShmemHugePages_bytes", + "node_memory_ShmemPmdMapped_bytes", + "node_memory_Shmem_bytes", + "node_memory_Slab_bytes", + "node_memory_SwapTotal_bytes", + "node_memory_VmallocChunk_bytes", + "node_memory_VmallocTotal_bytes", + "node_memory_VmallocUsed_bytes", + "node_memory_WritebackTmp_bytes", + "node_memory_Writeback_bytes", + "node_netstat_Icmp6_InErrors", + "node_netstat_Icmp6_InMsgs", + "node_netstat_Icmp6_OutMsgs", + "node_netstat_Icmp_InErrors", + "node_netstat_Icmp_InMsgs", + "node_netstat_Icmp_OutMsgs", + "node_netstat_IpExt_InOctets", + "node_netstat_IpExt_OutOctets", + "node_netstat_TcpExt_ListenDrops", + "node_netstat_TcpExt_ListenOverflows", + "node_netstat_TcpExt_TCPSynRetrans", + "node_netstat_Tcp_InErrs", + "node_netstat_Tcp_InSegs", + "node_netstat_Tcp_OutRsts", + "node_netstat_Tcp_OutSegs", + "node_netstat_Tcp_RetransSegs", + "node_netstat_Udp6_InDatagrams", + "node_netstat_Udp6_InErrors", + "node_netstat_Udp6_NoPorts", + "node_netstat_Udp6_OutDatagrams", + "node_netstat_Udp6_RcvbufErrors", + "node_netstat_Udp6_SndbufErrors", + "node_netstat_UdpLite_InErrors", + "node_netstat_Udp_InDatagrams", + "node_netstat_Udp_InErrors", + "node_netstat_Udp_NoPorts", + "node_netstat_Udp_OutDatagrams", + "node_netstat_Udp_RcvbufErrors", + "node_netstat_Udp_SndbufErrors", + "node_network_carrier", + "node_network_info", + "node_network_mtu_bytes", + "node_network_receive_bytes_total", + "node_network_receive_compressed_total", + "node_network_receive_drop_total", + "node_network_receive_errs_total", + "node_network_receive_fifo_total", + "node_network_receive_multicast_total", + "node_network_receive_packets_total", + "node_network_speed_bytes", + "node_network_transmit_bytes_total", + "node_network_transmit_compressed_total", + "node_network_transmit_drop_total", + "node_network_transmit_errs_total", + "node_network_transmit_fifo_total", + "node_network_transmit_packets_total", + "node_network_transmit_queue_length", + "node_network_up", + "node_nf_conntrack_entries", + "node_nf_conntrack_entries_limit", + "node_os_info", + "node_sockstat_FRAG6_inuse", + "node_sockstat_FRAG_inuse", + "node_sockstat_RAW6_inuse", + "node_sockstat_RAW_inuse", + "node_sockstat_TCP6_inuse", + "node_sockstat_TCP_alloc", + "node_sockstat_TCP_inuse", + "node_sockstat_TCP_mem", + "node_sockstat_TCP_mem_bytes", + "node_sockstat_TCP_orphan", + "node_sockstat_TCP_tw", + "node_sockstat_UDP6_inuse", + "node_sockstat_UDPLITE6_inuse", + "node_sockstat_UDPLITE_inuse", + "node_sockstat_UDP_inuse", + "node_sockstat_UDP_mem", + "node_sockstat_UDP_mem_bytes", + "node_sockstat_sockets_used", + "node_softnet_dropped_total", + "node_softnet_processed_total", + "node_softnet_times_squeezed_total", + "node_textfile_scrape_error", + "node_time_zone_offset_seconds", + "node_timex_estimated_error_seconds", + "node_timex_maxerror_seconds", + "node_timex_offset_seconds", + "node_timex_sync_status", + "node_uname_info", + "node_vmstat_oom_kill", + "node_vmstat_pgfault", + "node_vmstat_pgmajfault", + "node_vmstat_pgpgin", + "node_vmstat_pgpgout", + "node_vmstat_pswpin", + "node_vmstat_pswpout", + } + // TODO(marctc): Report list of failed metrics instead of one by one. + common.MimirMetricsTest(t, unixMetrics, []string{}, "unix_metrics") +} diff --git a/integration-tests/utils.go b/integration-tests/utils.go index d723a235235c..248e56eaaf8c 100644 --- a/integration-tests/utils.go +++ b/integration-tests/utils.go @@ -40,7 +40,7 @@ func setupEnvironment() { executeCommand("docker-compose", []string{"up", "-d"}, "Setting up environment with Docker Compose") } -func runSingleTest(testDir string) { +func runSingleTest(testDir string, port int) { info, err := os.Stat(testDir) if err != nil { panic(err) @@ -52,7 +52,7 @@ func runSingleTest(testDir string) { dirName := filepath.Base(testDir) var agentLogBuffer bytes.Buffer - cmd := exec.Command(agentBinaryPath, "run", "config.river") + cmd := exec.Command(agentBinaryPath, "run", "config.river", "--server.http.listen-addr", fmt.Sprintf("0.0.0.0:%d", port)) cmd.Dir = testDir cmd.Stdout = &agentLogBuffer cmd.Stderr = &agentLogBuffer @@ -96,14 +96,14 @@ func runAllTests() { panic(err) } var wg sync.WaitGroup - - for _, testDir := range testDirs { + port := 12345 + for i, testDir := range testDirs { fmt.Println("Running", testDir) wg.Add(1) - go func(td string) { + go func(td string, offset int) { defer wg.Done() - runSingleTest(td) - }(testDir) + runSingleTest(td, port+offset) + }(testDir, i) } wg.Wait() close(logChan)