janhoy commented on code in PR #5244: URL: https://github.com/apache/solr/pull/5244#discussion_r4410407633
########## solr/monitoring/dev/check-otel-parity.sh: ########## @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# check-otel-parity.sh — verify that the OTel collector re-exposes the same Prometheus +# metric names, types and label keys as Solr's own metrics endpoint. +# +# Usage: +# ./check-otel-parity.sh [SOLR_METRICS_URL] [COLLECTOR_METRICS_URL] +# +# Defaults: http://localhost:8983/solr/admin/metrics and http://localhost:9464/metrics +# (the bundled solr1 and otel-collector of this stack). Exit code 1 on any difference. +# +# Both endpoints are fetched with the Accept header Prometheus sends, and compared the +# way Prometheus ingests them: empty-valued labels are dropped, and the job/instance +# labels are ignored since Prometheus sets those itself on a direct scrape. Metrics +# that only exist on one side because the event never happened there (e.g. no errors +# yet) show up as differences; let the trafficgen run a minute first. + +set -euo pipefail + +SOLR_URL="${1:-http://localhost:8983/solr/admin/metrics}" +COLLECTOR_URL="${2:-http://localhost:9464/metrics}" +ACCEPT='application/openmetrics-text;version=1.0.0;q=0.5,application/openmetrics-text;version=0.0.1;q=0.4,text/plain;version=1.0.0;q=0.3,text/plain;version=0.0.4;q=0.2,*/*;q=0.1' + +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT + +curl -sf -H "Accept: $ACCEPT" "$SOLR_URL" > "$tmp/solr.txt" +curl -sf -H "Accept: $ACCEPT" "$COLLECTOR_URL" > "$tmp/collector.txt" + +# One line per series: <name> <sorted label keys>, plus one per family: TYPE <name> <type> +signature() { + grep -v '^#' "$1" | sed -E 's/^([a-zA-Z_:][a-zA-Z0-9_:]*)(\{([^}]*)\})?.*/\1 \3/' \ + | awk '{ n=split($2,kv,","); keys="" Review Comment: Fixed in 63bd0db1c4e. Confirmed it was not hypothetical: `jvm_memory_used_bytes{jvm_memory_pool_name="G1 Eden Space",jvm_memory_type="heap"}` and the same series without `jvm_memory_type` both reduced to `jvm_memory_used_bytes jvm_memory_pool_name`, so a dropped label key reported `Parity OK`. The label list is now parsed quote- and escape-aware (values are first reduced to `""`/`"x"`, after which splitting on commas is safe) and keys are sorted before comparing, so label reordering no longer shows up as a spurious diff either. Checked against fixtures both ways: the dropped-key case now exits 1, a reordered-label case passes. A failed fetch also reports why instead of exiting silently under `set -e`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
