Skip to content

Commit

Permalink
add initial integration tests for exporters (#6269)
Browse files Browse the repository at this point in the history
* add integration test for redis exporter
  • Loading branch information
marctc authored Feb 5, 2024
1 parent 755e1b7 commit 3e429ba
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
##
## test Run tests
## lint Lint code
## integration-tests Run integration tests
## integration-test Run integration tests
##
## Targets for building binaries:
##
Expand Down Expand Up @@ -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 .

Expand Down
2 changes: 0 additions & 2 deletions integration-tests/common/metrics_assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ services:
dockerfile: ./integration-tests/configs/prom-gen/Dockerfile
context: ..
ports:
- "9001:9001"
- "9001:9001"
redis:
image: redis:6.0.9-alpine
ports:
- "6379:6379"
2 changes: 1 addition & 1 deletion integration-tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions integration-tests/tests/redis/config.river
Original file line number Diff line number Diff line change
@@ -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",
}
}
32 changes: 32 additions & 0 deletions integration-tests/tests/redis/redis_metrics_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
23 changes: 23 additions & 0 deletions integration-tests/tests/unix/config.river
Original file line number Diff line number Diff line change
@@ -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",
}
}
164 changes: 164 additions & 0 deletions integration-tests/tests/unix/unix_metrics_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
14 changes: 7 additions & 7 deletions integration-tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3e429ba

Please sign in to comment.