From 8d54dd80c6a344b6c74e63de8ff322f10aecda73 Mon Sep 17 00:00:00 2001 From: Pete Wall Date: Thu, 19 Dec 2024 09:38:09 -0600 Subject: [PATCH 1/2] Add test showing how to use extraConfig and statsd Signed-off-by: Pete Wall --- .../statsd/deployments/grafana.yaml | 56 +++++++++++++++ .../statsd/deployments/prometheus.yaml | 69 +++++++++++++++++++ .../statsd/deployments/query-test.yaml | 42 +++++++++++ .../statsd/deployments/statsd-example.yaml | 68 ++++++++++++++++++ .../tests/integration/statsd/values.yaml | 35 ++++++++++ 5 files changed, 270 insertions(+) create mode 100644 charts/k8s-monitoring/tests/integration/statsd/deployments/grafana.yaml create mode 100644 charts/k8s-monitoring/tests/integration/statsd/deployments/prometheus.yaml create mode 100644 charts/k8s-monitoring/tests/integration/statsd/deployments/query-test.yaml create mode 100644 charts/k8s-monitoring/tests/integration/statsd/deployments/statsd-example.yaml create mode 100644 charts/k8s-monitoring/tests/integration/statsd/values.yaml diff --git a/charts/k8s-monitoring/tests/integration/statsd/deployments/grafana.yaml b/charts/k8s-monitoring/tests/integration/statsd/deployments/grafana.yaml new file mode 100644 index 000000000..b7476aef8 --- /dev/null +++ b/charts/k8s-monitoring/tests/integration/statsd/deployments/grafana.yaml @@ -0,0 +1,56 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: grafana +--- +apiVersion: source.toolkit.fluxcd.io/v1 +kind: HelmRepository +metadata: + name: grafana + namespace: grafana +spec: + interval: 1m + url: https://grafana.github.io/helm-charts +--- +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: grafana + namespace: grafana +spec: + interval: 1m + chart: + spec: + chart: grafana + sourceRef: + kind: HelmRepository + name: grafana + namespace: grafana + interval: 1m + values: + datasources: + datasources.yaml: + apiVersion: 1 + datasources: + - name: Prometheus + type: prometheus + url: http://prometheus-server.prometheus.svc:9090 + isDefault: true + basicAuth: true + basicAuthUser: promuser + jsonData: + tlsSkipVerify: true + secureJsonData: + basicAuthPassword: prometheuspassword + + - name: Loki + type: loki + url: http://loki-gateway.loki.svc:8080 + basicAuth: true + basicAuthUser: loki + jsonData: + httpHeaderName1: X-Scope-OrgID + secureJsonData: + basicAuthPassword: lokipassword + httpHeaderValue1: "1" diff --git a/charts/k8s-monitoring/tests/integration/statsd/deployments/prometheus.yaml b/charts/k8s-monitoring/tests/integration/statsd/deployments/prometheus.yaml new file mode 100644 index 000000000..4b3ca4444 --- /dev/null +++ b/charts/k8s-monitoring/tests/integration/statsd/deployments/prometheus.yaml @@ -0,0 +1,69 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: prometheus +--- +apiVersion: source.toolkit.fluxcd.io/v1 +kind: HelmRepository +metadata: + name: prometheus-community + namespace: prometheus +spec: + interval: 1m + url: https://prometheus-community.github.io/helm-charts +--- +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: prometheus + namespace: prometheus +spec: + interval: 1m + chart: + spec: + chart: prometheus + version: "^25" + sourceRef: + kind: HelmRepository + name: prometheus-community + namespace: prometheus + interval: 1m + values: + server: + extraFlags: + - enable-feature=otlp-write-receiver + - enable-feature=remote-write-receiver + + persistentVolume: + enabled: false + + probeHeaders: + - name: "Authorization" + value: "Basic cHJvbXVzZXI6cHJvbWV0aGV1c3Bhc3N3b3Jk" + + service: + servicePort: 9090 + + serverFiles: + prometheus.yml: + scrape_configs: [] + web.yml: + basic_auth_users: + promuser: $2a$12$1UJsAG4QnhjjDzqcSVkZmeDxxjgIFOAmzfuVTybTuhhDnYgfuAbAq # "prometheuspassword" + + configmapReload: + prometheus: + enabled: false + + alertmanager: + enabled: false + + kube-state-metrics: + enabled: false + + prometheus-node-exporter: + enabled: false + + prometheus-pushgateway: + enabled: false diff --git a/charts/k8s-monitoring/tests/integration/statsd/deployments/query-test.yaml b/charts/k8s-monitoring/tests/integration/statsd/deployments/query-test.yaml new file mode 100644 index 000000000..34988b204 --- /dev/null +++ b/charts/k8s-monitoring/tests/integration/statsd/deployments/query-test.yaml @@ -0,0 +1,42 @@ +--- +apiVersion: source.toolkit.fluxcd.io/v1 +kind: GitRepository +metadata: + name: k8s-monitoring-test +spec: + interval: 1m + url: https://github.com/grafana/k8s-monitoring-helm + ref: + branch: hackathon-2024-12-cluster-o-nimbus + ignore: | + /* + !/charts/k8s-monitoring-test +--- +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: k8s-monitoring-test +spec: + interval: 1m + chart: + spec: + chart: charts/k8s-monitoring-test + sourceRef: + kind: GitRepository + name: k8s-monitoring-test + interval: 1m + values: + tests: + - env: + CLUSTER: statsd-test + PROMETHEUS_URL: http://prometheus-server.prometheus.svc:9090/api/v1/query + PROMETHEUS_USER: promuser + PROMETHEUS_PASS: prometheuspassword + queries: + - query: example_gauge{cluster="$CLUSTER", job="integrations/statsd"} + type: promql + expect: + operator: == + value: 42 + - query: statsd_exporter_build_info{cluster="$CLUSTER", job="integrations/statsd"} + type: promql diff --git a/charts/k8s-monitoring/tests/integration/statsd/deployments/statsd-example.yaml b/charts/k8s-monitoring/tests/integration/statsd/deployments/statsd-example.yaml new file mode 100644 index 000000000..a9dae8872 --- /dev/null +++ b/charts/k8s-monitoring/tests/integration/statsd/deployments/statsd-example.yaml @@ -0,0 +1,68 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: statsd-example +data: + statsd-example.js: | + function sleep(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); + } + + async function main() { + console.log('Starting statsd example'); + const StatsD = require('node-statsd'); + const client = new StatsD({ + host: 'k8smon-alloy-receiver.default.svc', + port: 8125, + }); + + while (true) { + console.log('Sending metric'); + client.gauge('example.gauge', 42, function(error, bytes) { + if (error) { + console.error('Failed to send metric:', error); + } else { + console.log('Successfully sent', bytes, 'bytes'); + } + }); + await sleep(10000); + } + client.close(); + } + main(); +--- +apiVersion: v1 +kind: Pod +metadata: + name: statsd-example +spec: + initContainers: + - name: dependencies + image: node + command: + - bash + - -c + - | + npm install node-statsd + cp /src/statsd-example.js /workspace + workingDir: /workspace + volumeMounts: + - name: workspace + mountPath: /workspace + - name: source + mountPath: /src + containers: + - name: main + image: node + args: ["statsd-example.js"] + workingDir: /workspace + volumeMounts: + - name: workspace + mountPath: /workspace + volumes: + - name: workspace + emptyDir: {} + - name: source + configMap: + name: statsd-example \ No newline at end of file diff --git a/charts/k8s-monitoring/tests/integration/statsd/values.yaml b/charts/k8s-monitoring/tests/integration/statsd/values.yaml new file mode 100644 index 000000000..9be804f4f --- /dev/null +++ b/charts/k8s-monitoring/tests/integration/statsd/values.yaml @@ -0,0 +1,35 @@ +--- +cluster: + name: statsd-test + +destinations: + - name: localPrometheus + type: prometheus + url: http://prometheus-server.prometheus.svc:9090/api/v1/write + auth: + type: basic + username: promuser + password: prometheuspassword + +alloy-receiver: + enabled: true + alloy: + extraPorts: + - name: statsd-udp + port: 8125 + targetPort: 8125 + protocol: UDP + - name: statsd-tcp + port: 8125 + targetPort: 8125 + protocol: TCP + extraConfig: |- + prometheus.exporter.statsd "default" { + listen_udp = ":8125" + listen_tcp = ":8125" + parse_dogstatsd_tags = true + } + prometheus.scrape "statsd" { + targets = prometheus.exporter.statsd.default.targets + forward_to = [prometheus.remote_write.localprometheus.receiver] + } \ No newline at end of file From bf2b3ca37824eee9e064bb2276b7656a18884fb6 Mon Sep 17 00:00:00 2001 From: Pete Wall Date: Tue, 7 Jan 2025 13:16:14 -0600 Subject: [PATCH 2/2] Main, not hackathon Signed-off-by: Pete Wall --- .../tests/integration/statsd/deployments/query-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/k8s-monitoring/tests/integration/statsd/deployments/query-test.yaml b/charts/k8s-monitoring/tests/integration/statsd/deployments/query-test.yaml index 34988b204..cf073ca8c 100644 --- a/charts/k8s-monitoring/tests/integration/statsd/deployments/query-test.yaml +++ b/charts/k8s-monitoring/tests/integration/statsd/deployments/query-test.yaml @@ -7,7 +7,7 @@ spec: interval: 1m url: https://github.com/grafana/k8s-monitoring-helm ref: - branch: hackathon-2024-12-cluster-o-nimbus + branch: main ignore: | /* !/charts/k8s-monitoring-test