diff --git a/.github/renovate-tracked-deps.json b/.github/renovate-tracked-deps.json index eebbdf0d6..fba9d60bd 100644 --- a/.github/renovate-tracked-deps.json +++ b/.github/renovate-tracked-deps.json @@ -103,6 +103,11 @@ "maven" ] }, + "ci/oats/docker-compose.lgtm.yml": { + "docker-compose": [ + "docker.io/grafana/otel-lgtm" + ] + }, "examples/example-custom-buckets/docker-compose.yaml": { "docker-compose": [ "eclipse-temurin", @@ -169,6 +174,7 @@ "zizmor" ], "regex": [ + "gcx", "grafana/docker-otel-lgtm", "micrometer-metrics/micrometer", "prometheus/jmx_exporter" diff --git a/examples/example-exporter-opentelemetry/oats-tests/agent/docker-compose.yml b/examples/example-exporter-opentelemetry/oats-tests/agent/docker-compose.yml index 2b820bdea..46a541f54 100644 --- a/examples/example-exporter-opentelemetry/oats-tests/agent/docker-compose.yml +++ b/examples/example-exporter-opentelemetry/oats-tests/agent/docker-compose.yml @@ -4,7 +4,7 @@ version: "3.4" services: java: build: - context: ../.. + context: ../../examples/example-exporter-opentelemetry dockerfile: oats-tests/agent/Dockerfile environment: OTEL_SERVICE_NAME: "rolldice" diff --git a/examples/example-exporter-opentelemetry/oats-tests/agent/oats.yaml b/examples/example-exporter-opentelemetry/oats-tests/agent/oats.yaml index 899d1cd5d..a6362a747 100644 --- a/examples/example-exporter-opentelemetry/oats-tests/agent/oats.yaml +++ b/examples/example-exporter-opentelemetry/oats-tests/agent/oats.yaml @@ -1,12 +1,16 @@ -# OATS is an acceptance testing framework for OpenTelemetry - -# https://github.com/grafana/oats/tree/main/yaml -oats-schema-version: 2 -docker-compose: - files: - - ./docker-compose.yml +oats: 2 +name: java agent exporter preserves target_info identity +fixture: + type: compose + template: lgtm + compose_file: docker-compose.yml +seed: + type: app expected: - custom-checks: - - script: ./service_instance_id_check.py metrics: - - promql: "uptime_seconds_total{}" - value: ">= 0" + - promql: 'uptime_seconds_total{}' + value: '>= 0' + - promql: 'count(count by(instance) (target_info{service_name!="otelcol-contrib"}))' + value: '== 1' + - promql: 'count(target_info{service_name!="otelcol-contrib"})' + value: '== 2' diff --git a/examples/example-exporter-opentelemetry/oats-tests/agent/service_instance_id_check.py b/examples/example-exporter-opentelemetry/oats-tests/agent/service_instance_id_check.py deleted file mode 100755 index 35ff88b8d..000000000 --- a/examples/example-exporter-opentelemetry/oats-tests/agent/service_instance_id_check.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python3 -""" -Check if the service instance id is present in the exported data. -Returns 0 if the service instance id is present in the exported data. -""" - -import json -import urllib.parse -from urllib.request import urlopen - - -def get_json(url): - with urlopen(url) as response: - return json.loads(response.read().decode("utf-8")) - - -def main(): - # Query Prometheus for target_info - res = get_json("http://localhost:9090/api/v1/query?query=target_info") - - # Uncomment for local debugging - # with open('example_target_info.json') as f: - # res = json.load(f) - - instance_ids = { - r["metric"]["instance"] - for r in res["data"]["result"] - if r["metric"].get("service_name") != "otelcol-contrib" - } - instance_ids = list(instance_ids) - - print(f"Instance ids found:{instance_ids}") - if len(instance_ids) > 1: - print("More than one instance id found") - print(res) - - # Both the agent and the exporter should report the same instance id - assert len(instance_ids) == 1, "Expected exactly one instance id" - - query = f'target_info{{instance="{instance_ids[0]}"}}' - encoded_query = urllib.parse.quote_plus(query) - res = get_json(f"http://localhost:9090/api/v1/query?query={encoded_query}") - - infos = res["data"]["result"] - print(infos) - - # They should not have the same target info (e.g. only the agent has telemetry_distro_name) - assert len(infos) == 2, "Expected two target info results" - - -if __name__ == "__main__": - main() diff --git a/examples/example-exporter-opentelemetry/oats-tests/http/docker-compose.yml b/examples/example-exporter-opentelemetry/oats-tests/http/docker-compose.yml index 889278010..2743dfef7 100644 --- a/examples/example-exporter-opentelemetry/oats-tests/http/docker-compose.yml +++ b/examples/example-exporter-opentelemetry/oats-tests/http/docker-compose.yml @@ -4,7 +4,7 @@ version: "3.4" services: java: build: - context: ../.. + context: ../../examples/example-exporter-opentelemetry dockerfile: oats-tests/http/Dockerfile environment: OTEL_SERVICE_NAME: "rolldice" diff --git a/examples/example-exporter-opentelemetry/oats-tests/http/oats.yaml b/examples/example-exporter-opentelemetry/oats-tests/http/oats.yaml index dbcfcf84f..98844a270 100644 --- a/examples/example-exporter-opentelemetry/oats-tests/http/oats.yaml +++ b/examples/example-exporter-opentelemetry/oats-tests/http/oats.yaml @@ -1,10 +1,12 @@ -# OATS is an acceptance testing framework for OpenTelemetry - -# https://github.com/grafana/oats/tree/main/yaml -oats-schema-version: 2 -docker-compose: - files: - - ./docker-compose.yml +oats: 2 +name: http protobuf exporter emits uptime metric +fixture: + type: compose + template: lgtm + compose_file: docker-compose.yml +seed: + type: app expected: metrics: - - promql: "uptime_seconds_total{}" - value: ">= 0" + - promql: 'uptime_seconds_total{}' + value: '>= 0' diff --git a/mise.toml b/mise.toml index 3e1a4b62c..538da7f54 100644 --- a/mise.toml +++ b/mise.toml @@ -1,6 +1,6 @@ [tools] "go:github.com/grafana/oats" = "0.7.0" -hugo = "0.163.0" +hugo = "0.163.2" java = "temurin-25.0.3+9.0.LTS" node = "24.16.0" protoc = "35" @@ -9,14 +9,14 @@ protoc = "35" actionlint = "1.7.12" "aqua:grafana/flint" = "0.22.5" "aqua:jonwiggins/xmloxide" = "v0.4.3" -"aqua:owenlamont/ryl" = "0.14.0" -biome = "2.4.16" +"aqua:owenlamont/ryl" = "0.18.1" +biome = "2.5.0" editorconfig-checker = "3.7.0" google-java-format = "1.35.0" lychee = "0.24.2" -"npm:renovate" = "43.212.4" -ruff = "0.15.16" -rumdl = "0.2.9" +"npm:renovate" = "43.220.0" +ruff = "0.15.17" +rumdl = "v0.2.17" shellcheck = "v0.11.0" shfmt = "3.13.1" taplo = "0.10.0" @@ -93,7 +93,39 @@ run = "flint run --fix" [tasks.acceptance-test] description = "Run OATs acceptance tests" depends = "build" -run = "oats -lgtm-version $LGTM_VERSION -timeout 5m examples/" +run = """ +# renovate: datasource=github-releases depName=gcx packageName=grafana/gcx +export GCX_VERSION=v0.4.0 +gotmp="" + +if ! command -v go >/dev/null 2>&1; then + goversion="1.25.4" + arch="$(uname -m)" + case "$arch" in + x86_64|amd64) goarch="amd64" ;; + aarch64|arm64) goarch="arm64" ;; + *) echo "unsupported architecture: $arch" >&2; exit 1 ;; + esac + gotmp="$(mktemp -d)" + curl -fsSL "https://go.dev/dl/go${goversion}.linux-${goarch}.tar.gz" -o "$gotmp/go.tgz" + tar -C "$gotmp" -xzf "$gotmp/go.tgz" + export PATH="$gotmp/go/bin:$PATH" +fi + +go install "github.com/grafana/gcx/cmd/gcx@${GCX_VERSION}" + +workdir="$(mktemp -d)" +trap 'rm -rf "$workdir" ${gotmp:+"$gotmp"}' EXIT +git clone --depth 1 --branch v2 https://github.com/grafana/oats "$workdir/oats-src" +GOWORK=off go -C "$workdir/oats-src" build -o "$workdir/oats" ./cmd/v2 + +REAL_GCX_BIN="$(go env GOPATH)/bin/gcx" \ + "$workdir/oats" \ + --config oats.toml \ + --gcx ./ci/oats/gcx-wrapper.sh \ + --no-cache \ + --timeout=5m +""" [tasks.javadoc] description = "Generate Javadoc" diff --git a/oats.toml b/oats.toml new file mode 100644 index 000000000..f7e9fb212 --- /dev/null +++ b/oats.toml @@ -0,0 +1,7 @@ +cases = [ + "examples/example-exporter-opentelemetry/oats-tests/http/oats.yaml", + "examples/example-exporter-opentelemetry/oats-tests/agent/oats.yaml", +] + +[meta] +version = 2