From 644fa14e27f8d0a9f8e9b65b8093667f3f5d173c Mon Sep 17 00:00:00 2001 From: Erik Baranowski <39704712+erikbaranowski@users.noreply.github.com> Date: Thu, 4 Apr 2024 15:36:58 -0400 Subject: [PATCH] fix up windows tests for static converter by breaking them out from linux specific tests (#6822) Signed-off-by: Erik Baranowski <39704712+erikbaranowski@users.noreply.github.com> --- .../promtailconvert_windows_test.go | 3 +- .../windowsevents.river | 0 .../windowsevents.yaml | 0 .../windowsevents_relabel.river | 0 .../windowsevents_relabel.yaml | 0 .../staticconvert/staticconvert_test.go | 9 +- .../staticconvert_windows_test.go | 17 +++ .../promtail_prom.diags | 0 .../promtail_prom.river | 0 .../promtail_prom.yaml | 0 .../testdata_windows/promtail_prom.diags | 1 + .../testdata_windows/promtail_prom.river | 132 ++++++++++++++++++ .../testdata_windows/promtail_prom.yaml | 76 ++++++++++ 13 files changed, 231 insertions(+), 7 deletions(-) rename internal/converter/internal/promtailconvert/{testdatawindows => testdata_windows}/windowsevents.river (100%) rename internal/converter/internal/promtailconvert/{testdatawindows => testdata_windows}/windowsevents.yaml (100%) rename internal/converter/internal/promtailconvert/{testdatawindows => testdata_windows}/windowsevents_relabel.river (100%) rename internal/converter/internal/promtailconvert/{testdatawindows => testdata_windows}/windowsevents_relabel.yaml (100%) create mode 100644 internal/converter/internal/staticconvert/staticconvert_windows_test.go rename internal/converter/internal/staticconvert/{testdata => testdata_linux}/promtail_prom.diags (100%) rename internal/converter/internal/staticconvert/{testdata => testdata_linux}/promtail_prom.river (100%) rename internal/converter/internal/staticconvert/{testdata => testdata_linux}/promtail_prom.yaml (100%) create mode 100644 internal/converter/internal/staticconvert/testdata_windows/promtail_prom.diags create mode 100644 internal/converter/internal/staticconvert/testdata_windows/promtail_prom.river create mode 100644 internal/converter/internal/staticconvert/testdata_windows/promtail_prom.yaml diff --git a/internal/converter/internal/promtailconvert/promtailconvert_windows_test.go b/internal/converter/internal/promtailconvert/promtailconvert_windows_test.go index 82d85b7e13aa..4e6f3ead80e6 100644 --- a/internal/converter/internal/promtailconvert/promtailconvert_windows_test.go +++ b/internal/converter/internal/promtailconvert/promtailconvert_windows_test.go @@ -11,5 +11,6 @@ import ( ) func TestConvert(t *testing.T) { - test_common.TestDirectory(t, "testdatawindows", ".yaml", true, []string{}, promtailconvert.Convert) + test_common.TestDirectory(t, "testdata", ".yaml", true, []string{}, promtailconvert.Convert) + test_common.TestDirectory(t, "testdata_windows", ".yaml", true, []string{}, promtailconvert.Convert) } diff --git a/internal/converter/internal/promtailconvert/testdatawindows/windowsevents.river b/internal/converter/internal/promtailconvert/testdata_windows/windowsevents.river similarity index 100% rename from internal/converter/internal/promtailconvert/testdatawindows/windowsevents.river rename to internal/converter/internal/promtailconvert/testdata_windows/windowsevents.river diff --git a/internal/converter/internal/promtailconvert/testdatawindows/windowsevents.yaml b/internal/converter/internal/promtailconvert/testdata_windows/windowsevents.yaml similarity index 100% rename from internal/converter/internal/promtailconvert/testdatawindows/windowsevents.yaml rename to internal/converter/internal/promtailconvert/testdata_windows/windowsevents.yaml diff --git a/internal/converter/internal/promtailconvert/testdatawindows/windowsevents_relabel.river b/internal/converter/internal/promtailconvert/testdata_windows/windowsevents_relabel.river similarity index 100% rename from internal/converter/internal/promtailconvert/testdatawindows/windowsevents_relabel.river rename to internal/converter/internal/promtailconvert/testdata_windows/windowsevents_relabel.river diff --git a/internal/converter/internal/promtailconvert/testdatawindows/windowsevents_relabel.yaml b/internal/converter/internal/promtailconvert/testdata_windows/windowsevents_relabel.yaml similarity index 100% rename from internal/converter/internal/promtailconvert/testdatawindows/windowsevents_relabel.yaml rename to internal/converter/internal/promtailconvert/testdata_windows/windowsevents_relabel.yaml diff --git a/internal/converter/internal/staticconvert/staticconvert_test.go b/internal/converter/internal/staticconvert/staticconvert_test.go index a38de5d0184f..92c6b1e3eda8 100644 --- a/internal/converter/internal/staticconvert/staticconvert_test.go +++ b/internal/converter/internal/staticconvert/staticconvert_test.go @@ -1,7 +1,8 @@ +//go:build linux + package staticconvert_test import ( - "runtime" "testing" "github.com/grafana/agent/internal/converter/internal/staticconvert" @@ -12,9 +13,5 @@ import ( func TestConvert(t *testing.T) { test_common.TestDirectory(t, "testdata", ".yaml", true, []string{"-config.expand-env"}, staticconvert.Convert) test_common.TestDirectory(t, "testdata-v2", ".yaml", true, []string{"-enable-features", "integrations-next", "-config.expand-env"}, staticconvert.Convert) - - if runtime.GOOS == "windows" { - test_common.TestDirectory(t, "testdata_windows", ".yaml", true, []string{}, staticconvert.Convert) - test_common.TestDirectory(t, "testdata-v2_windows", ".yaml", true, []string{"-enable-features", "integrations-next"}, staticconvert.Convert) - } + test_common.TestDirectory(t, "testdata_linux", ".yaml", true, []string{"-config.expand-env"}, staticconvert.Convert) } diff --git a/internal/converter/internal/staticconvert/staticconvert_windows_test.go b/internal/converter/internal/staticconvert/staticconvert_windows_test.go new file mode 100644 index 000000000000..5cf536d3c623 --- /dev/null +++ b/internal/converter/internal/staticconvert/staticconvert_windows_test.go @@ -0,0 +1,17 @@ +//go:build windows + +package staticconvert_test + +import ( + "testing" + + "github.com/grafana/agent/internal/converter/internal/staticconvert" + "github.com/grafana/agent/internal/converter/internal/test_common" + _ "github.com/grafana/agent/internal/static/metrics/instance" // Imported to override default values via the init function. +) + +func TestConvert(t *testing.T) { + test_common.TestDirectory(t, "testdata", ".yaml", true, []string{"-config.expand-env"}, staticconvert.Convert) + test_common.TestDirectory(t, "testdata-v2_windows", ".yaml", true, []string{"-enable-features", "integrations-next"}, staticconvert.Convert) + test_common.TestDirectory(t, "testdata_windows", ".yaml", true, []string{"-config.expand-env"}, staticconvert.Convert) +} diff --git a/internal/converter/internal/staticconvert/testdata/promtail_prom.diags b/internal/converter/internal/staticconvert/testdata_linux/promtail_prom.diags similarity index 100% rename from internal/converter/internal/staticconvert/testdata/promtail_prom.diags rename to internal/converter/internal/staticconvert/testdata_linux/promtail_prom.diags diff --git a/internal/converter/internal/staticconvert/testdata/promtail_prom.river b/internal/converter/internal/staticconvert/testdata_linux/promtail_prom.river similarity index 100% rename from internal/converter/internal/staticconvert/testdata/promtail_prom.river rename to internal/converter/internal/staticconvert/testdata_linux/promtail_prom.river diff --git a/internal/converter/internal/staticconvert/testdata/promtail_prom.yaml b/internal/converter/internal/staticconvert/testdata_linux/promtail_prom.yaml similarity index 100% rename from internal/converter/internal/staticconvert/testdata/promtail_prom.yaml rename to internal/converter/internal/staticconvert/testdata_linux/promtail_prom.yaml diff --git a/internal/converter/internal/staticconvert/testdata_windows/promtail_prom.diags b/internal/converter/internal/staticconvert/testdata_windows/promtail_prom.diags new file mode 100644 index 000000000000..a4a05d1a3b58 --- /dev/null +++ b/internal/converter/internal/staticconvert/testdata_windows/promtail_prom.diags @@ -0,0 +1 @@ +(Warning) Please review your agent command line flags and ensure they are set in your Flow mode config file where necessary. \ No newline at end of file diff --git a/internal/converter/internal/staticconvert/testdata_windows/promtail_prom.river b/internal/converter/internal/staticconvert/testdata_windows/promtail_prom.river new file mode 100644 index 000000000000..c0bd2f9e7657 --- /dev/null +++ b/internal/converter/internal/staticconvert/testdata_windows/promtail_prom.river @@ -0,0 +1,132 @@ +discovery.consul "metrics_name_jobName" { + services = ["myapp"] +} + +prometheus.scrape "metrics_name_jobName" { + targets = concat( + discovery.consul.metrics_name_jobName.targets, + [{ + __address__ = "localhost:9099", + }], + [{ + __address__ = "localhost:9101", + }], + ) + forward_to = [prometheus.remote_write.metrics_name.receiver] + job_name = "jobName" +} + +prometheus.remote_write "metrics_name" { + endpoint { + name = "name-149bbd" + url = "http://localhost:9009/api/prom/push" + + queue_config { } + + metadata_config { } + } +} + +discovery.consul "logs_name_jobName" { + datacenter = "bigdata" + tag_separator = ";" + scheme = "sketchy" + username = "toby" + password = "this_password_is_safe_innit?" + allow_stale = false + services = ["myapp"] + tags = ["better", "faster", "stronger"] + node_meta = { + what = "this", + where = "here", + } + refresh_interval = "10m0s" + + basic_auth { + username = "toby" + password = "this_password_is_safe_innit?" + } +} + +discovery.relabel "logs_name_jobName" { + targets = discovery.consul.logs_name_jobName.targets + + rule { + source_labels = ["host"] + target_label = "hostname" + } +} + +local.file_match "logs_name_jobName" { + path_targets = discovery.relabel.logs_name_jobName.output +} + +loki.source.file "logs_name_jobName" { + targets = local.file_match.logs_name_jobName.targets + forward_to = [loki.write.logs_name.receiver] + + file_watch { + min_poll_frequency = "1s" + max_poll_frequency = "5s" + } + legacy_positions_file = "\\path\\name.yml" +} + +loki.write "logs_name" { + endpoint { + url = "http://localhost/loki/api/v1/push" + } + external_labels = {} +} + +discovery.consul "logs_name2_jobName" { + datacenter = "bigdata" + tag_separator = ";" + scheme = "sketchy" + username = "toby" + password = "this_password_is_safe_innit?" + allow_stale = false + services = ["myapp"] + tags = ["better", "faster", "stronger"] + node_meta = { + what = "this", + where = "here", + } + refresh_interval = "10m0s" + + basic_auth { + username = "toby" + password = "this_password_is_safe_innit?" + } +} + +discovery.relabel "logs_name2_jobName" { + targets = discovery.consul.logs_name2_jobName.targets + + rule { + source_labels = ["host"] + target_label = "hostname" + } +} + +local.file_match "logs_name2_jobName" { + path_targets = discovery.relabel.logs_name2_jobName.output +} + +loki.source.file "logs_name2_jobName" { + targets = local.file_match.logs_name2_jobName.targets + forward_to = [loki.write.logs_name2.receiver] + + file_watch { + min_poll_frequency = "1s" + max_poll_frequency = "5s" + } + legacy_positions_file = "\\path\\name2.yml" +} + +loki.write "logs_name2" { + endpoint { + url = "http://localhost/loki/api/v1/push" + } + external_labels = {} +} diff --git a/internal/converter/internal/staticconvert/testdata_windows/promtail_prom.yaml b/internal/converter/internal/staticconvert/testdata_windows/promtail_prom.yaml new file mode 100644 index 000000000000..34f29485ab3f --- /dev/null +++ b/internal/converter/internal/staticconvert/testdata_windows/promtail_prom.yaml @@ -0,0 +1,76 @@ +metrics: + global: + remote_write: + - url: http://localhost:9009/api/prom/push + configs: + - name: name + host_filter: false + scrape_configs: + - job_name: 'jobName' + static_configs: + - targets: ['localhost:9099','localhost:9101'] + consul_sd_configs: + - server: 'localhost:8500' + services: ['myapp'] + +logs: + global: + file_watch_config: + min_poll_frequency: 1s + max_poll_frequency: 5s + positions_directory: /path + configs: + - name: name + clients: + - url: http://localhost/loki/api/v1/push + scrape_configs: + - job_name: jobName + consul_sd_configs: + - server: 'localhost:8500' + datacenter: bigdata + scheme: sketchy + username: toby + password: this_password_is_safe_innit? + tags: + - better + - faster + - stronger + services: [ 'myapp' ] + node_meta: + where: here + what: this + tag_separator: ";" + allow_stale: false + refresh_interval: 10m + + relabel_configs: + - source_labels: + - host + target_label: hostname + - name: name2 + clients: + - url: http://localhost/loki/api/v1/push + scrape_configs: + - job_name: jobName + consul_sd_configs: + - server: 'localhost:8500' + datacenter: bigdata + scheme: sketchy + username: toby + password: this_password_is_safe_innit? + tags: + - better + - faster + - stronger + services: [ 'myapp' ] + node_meta: + where: here + what: this + tag_separator: ";" + allow_stale: false + refresh_interval: 10m + + relabel_configs: + - source_labels: + - host + target_label: hostname \ No newline at end of file