-
Notifications
You must be signed in to change notification settings - Fork 707
test(prometheus.exporter.cadvisor): Add integration test #7039
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8333c0b
test(prometheus.exporter.cadvisor): Add docker integration test (POC)
dehaansa 06a31c2
test(prometheus.exporter.cadvisor): Pin metric assertion list
dehaansa 2a1feca
Merge branch 'main' into poc/cadvisor-integration-test
dehaansa bdc7ff9
test(prometheus.exporter.cadvisor): Move integration test to k8s harn…
dehaansa 4277402
Merge branch 'poc/cadvisor-integration-test' of https://github.com/gr…
dehaansa 8e6e232
remove unneeded comment
dehaansa f9733e8
fix(prometheus.exporter.cadvisor): Drop read-only /var/run mount that…
dehaansa a368a46
test(prometheus.exporter.cadvisor): Check filesystem values and conta…
dehaansa a51e53a
test(prometheus.exporter.cadvisor): Trim values comment, mount contai…
dehaansa 9e41511
test(prometheus.exporter.cadvisor): Assert more container labels
dehaansa 7eabf7a
test(prometheus.exporter.cadvisor): Check all container labels in one…
dehaansa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
integration-tests/k8s/tests/prometheus-exporter-cadvisor/config/alloy-values.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # The containerd socket lets cAdvisor's containerd plugin resolve pod metadata | ||
| # and attach container_label_* labels. Only the socket is mounted, not all of | ||
| # /var/run: a read-only /var/run blocks Kubernetes from mounting the service | ||
| # account token, so the pod would fail to start. | ||
| controller: | ||
| type: daemonset | ||
| volumes: | ||
| extra: | ||
| - name: rootfs | ||
| hostPath: | ||
| path: / | ||
| - name: sys | ||
| hostPath: | ||
| path: /sys | ||
| - name: disk | ||
| hostPath: | ||
| path: /dev/disk | ||
| - name: containerd-sock | ||
| hostPath: | ||
| path: /run/containerd/containerd.sock | ||
| type: Socket | ||
|
|
||
| alloy: | ||
| stabilityLevel: experimental | ||
| initialDelaySeconds: 1 | ||
| # The raw cgroup driver needs a privileged container to read /sys/fs/cgroup. | ||
| securityContext: | ||
| privileged: true | ||
| mounts: | ||
|
thampiotr marked this conversation as resolved.
|
||
| extra: | ||
| - name: rootfs | ||
| mountPath: /rootfs | ||
| readOnly: true | ||
| - name: sys | ||
| mountPath: /sys | ||
| readOnly: true | ||
| - name: disk | ||
| mountPath: /dev/disk | ||
| readOnly: true | ||
| - name: containerd-sock | ||
| mountPath: /run/containerd/containerd.sock | ||
| readOnly: true | ||
33 changes: 33 additions & 0 deletions
33
integration-tests/k8s/tests/prometheus-exporter-cadvisor/config/config.alloy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| logging { | ||
| level = "debug" | ||
| } | ||
|
|
||
| prometheus.exporter.cadvisor "test" { | ||
| storage_duration = "1m" | ||
| } | ||
|
|
||
| prometheus.scrape "cadvisor" { | ||
| targets = prometheus.exporter.cadvisor.test.targets | ||
| forward_to = [prometheus.relabel.cadvisor.receiver] | ||
| scrape_interval = "1s" | ||
| scrape_timeout = "500ms" | ||
| } | ||
|
|
||
| prometheus.relabel "cadvisor" { | ||
| forward_to = [prometheus.remote_write.mimir.receiver] | ||
| // The k8s harness filters series on alloy_test_name. | ||
| rule { | ||
| action = "replace" | ||
| target_label = "alloy_test_name" | ||
| replacement = "cadvisor" | ||
| } | ||
| } | ||
|
|
||
| prometheus.remote_write "mimir" { | ||
| endpoint { | ||
| url = "http://mimir:9009/api/v1/push" | ||
| queue_config { | ||
| max_samples_per_send = 100 | ||
| } | ||
| } | ||
| } |
99 changes: 99 additions & 0 deletions
99
integration-tests/k8s/tests/prometheus-exporter-cadvisor/k8s_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package prometheusexportercadvisor | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/grafana/alloy/integration-tests/k8s/deps" | ||
| "github.com/grafana/alloy/integration-tests/k8s/harness" | ||
| ) | ||
|
|
||
| func TestPrometheusExporterCadvisor(t *testing.T) { | ||
| ns := deps.NewNamespace(deps.NamespaceOptions{ | ||
| Name: "test-prometheus-exporter-cadvisor", | ||
| Labels: map[string]string{"alloy-integration-test": "true"}, | ||
| }) | ||
| mimir := deps.NewMimir(deps.MimirOptions{Namespace: ns.Name()}) | ||
| alloy := deps.NewAlloy(deps.AlloyOptions{ | ||
| Namespace: ns.Name(), | ||
| Release: "alloy-test-prometheus-exporter-cadvisor", | ||
| ConfigPath: "./config/config.alloy", | ||
| ValuesPath: "./config/alloy-values.yaml", | ||
| }) | ||
| harness.Setup(t, harness.Options{ | ||
| Dependencies: []harness.Dependency{ns, mimir, alloy}, | ||
| }) | ||
|
|
||
| // Covers the cAdvisor collector families: version, cpu, memory, filesystem, | ||
| // network, and blkio. | ||
| // | ||
| // Two families are left out on purpose: | ||
| // - container_pressure_* (PSI) needs kernel CONFIG_PSI. Not every host has it. | ||
| // - container_health_state needs a container with a Docker HEALTHCHECK. It | ||
| // depends on the sibling workloads, not the exporter. | ||
| mimir.QueryMetrics(t, "cadvisor", []string{ | ||
| "cadvisor_build_info", | ||
| "cadvisor_version_info", | ||
| "container_blkio_device_usage_total", | ||
| "container_cpu_load_average_10s", | ||
| "container_cpu_load_d_average_10s", | ||
| "container_cpu_system_seconds_total", | ||
| "container_cpu_usage_seconds_total", | ||
| "container_cpu_user_seconds_total", | ||
| "container_fs_inodes_free", | ||
| "container_fs_inodes_total", | ||
| "container_fs_io_current", | ||
| "container_fs_io_time_seconds_total", | ||
| "container_fs_io_time_weighted_seconds_total", | ||
| "container_fs_limit_bytes", | ||
| "container_fs_read_seconds_total", | ||
| "container_fs_reads_bytes_total", | ||
| "container_fs_reads_merged_total", | ||
| "container_fs_reads_total", | ||
| "container_fs_sector_reads_total", | ||
| "container_fs_sector_writes_total", | ||
| "container_fs_usage_bytes", | ||
| "container_fs_write_seconds_total", | ||
| "container_fs_writes_bytes_total", | ||
| "container_fs_writes_merged_total", | ||
| "container_fs_writes_total", | ||
| "container_last_seen", | ||
| "container_memory_cache", | ||
| "container_memory_failcnt", | ||
| "container_memory_failures_total", | ||
| "container_memory_kernel_usage", | ||
| "container_memory_mapped_file", | ||
| "container_memory_max_usage_bytes", | ||
| "container_memory_rss", | ||
| "container_memory_swap", | ||
| "container_memory_total_active_file_bytes", | ||
| "container_memory_total_inactive_file_bytes", | ||
| "container_memory_usage_bytes", | ||
| "container_memory_working_set_bytes", | ||
| "container_network_receive_bytes_total", | ||
| "container_network_receive_errors_total", | ||
| "container_network_receive_packets_dropped_total", | ||
| "container_network_receive_packets_total", | ||
| "container_network_transmit_bytes_total", | ||
| "container_network_transmit_errors_total", | ||
| "container_network_transmit_packets_dropped_total", | ||
| "container_network_transmit_packets_total", | ||
| "container_oom_events_total", | ||
| }) | ||
|
|
||
| // The filesystem metrics must report real data, not just be present. These | ||
| // come from the root cgroup's machine filesystem, so they are always > 0 and | ||
| // prove the explicit filesystem-plugin wiring produces values. | ||
| mimir.QueryPositive(t, "cadvisor", []string{ | ||
| "container_fs_usage_bytes", | ||
| "container_fs_limit_bytes", | ||
| }) | ||
|
|
||
| // The containerd socket lets cAdvisor resolve pod metadata, so container | ||
| // labels are attached. Kubernetes sets these io.kubernetes.* labels on every | ||
| // container, so a single series carries all three when the plugin works. | ||
| mimir.QueryLabelsPresent(t, "cadvisor", | ||
| "container_label_io_kubernetes_pod_name", | ||
| "container_label_io_kubernetes_pod_namespace", | ||
| "container_label_io_kubernetes_container_name", | ||
| ) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: That's a pretty narrow solution. I was thinking of something we can use more broadly like
QueryMetricWithLabels(t, metricName string, labelNames ...string)that would check the labels exist for the given metric name.Leaving this as optional nit, because that can be done as a refactor as we add other tests.