From 07c34ee59ef613e6128d867d407ce49f5484a65e Mon Sep 17 00:00:00 2001 From: Harish Shan <140232061+perhapsmaple@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:33:21 -0400 Subject: [PATCH] Add shell script to ensure consistent version of OTEL semconv (#4652) ## Which problem is this PR solving? Resolves #4646 ## Description of the changes - Added scripts/check-semconv-version.sh to search the code for all usages of "go.opentelemetry.io/otel/semconv/v1.xx.x" and fail if they are not identical, with an error message and the source files along with their respective versions. - Added scripts/update-semconv-version.sh to fetch the latest version of semconv with curl and replace all references of "go.opentelemetry.io/otel/semconv/v1.xx.x" with the latest version. ## How was this change tested? I have tested the changes locally by modifying import statements ![Mismatch_Version_Test](https://github.com/jaegertracing/jaeger/assets/140232061/769ae5cd-0d3e-4f45-b5a1-e5cadb6b248e) ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Harish Shan <140232061+perhapsmaple@users.noreply.github.com> --- Makefile | 1 + scripts/check-semconv-version.sh | 23 +++++++++++++++++++++++ scripts/update-semconv-version.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100755 scripts/check-semconv-version.sh create mode 100755 scripts/update-semconv-version.sh diff --git a/Makefile b/Makefile index 7eb51691281..0583b836c5b 100644 --- a/Makefile +++ b/Makefile @@ -164,6 +164,7 @@ lint: ./scripts/updateLicenses.sh > $(FMT_LOG) ./scripts/import-order-cleanup.sh stdout > $(IMPORT_LOG) @[ ! -s "$(FMT_LOG)" -a ! -s "$(IMPORT_LOG)" ] || (echo "License check or import ordering failures, run 'make fmt'" | cat - $(FMT_LOG) $(IMPORT_LOG) && false) + ./scripts/check-semconv-version.sh .PHONY: build-examples build-examples: diff --git a/scripts/check-semconv-version.sh b/scripts/check-semconv-version.sh new file mode 100755 index 00000000000..1e4140c0d20 --- /dev/null +++ b/scripts/check-semconv-version.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +declare -A semconv_map + +package_name="go.opentelemetry.io/otel/semconv" +version_regex="v[0-9]\.[0-9]\+\.[0-9]\+" + +while IFS=: read -r file_name package_string; do + semconv_map["$file_name"]="${package_string##*/}" +done < <(find . -type f -name "*.go" -exec grep -o -H "$package_name/$version_regex" {} +) + +semconv_versions=($(printf "%s\n" "${semconv_map[@]}" | sort -u)) + +if [ ${#semconv_versions[@]} -gt 1 ]; then + echo "Error: semconv version mismatch detected." + { + for key in "${!semconv_map[@]}"; do + printf "Source File: %-50s | Semconv Version: %s\n" "$key" "${semconv_map[$key]}" + done + } | column -t -s '|' + echo "Run ./scripts/update-semconv-version.sh to update semconv to latest version." + exit 1 +fi diff --git a/scripts/update-semconv-version.sh b/scripts/update-semconv-version.sh new file mode 100755 index 00000000000..bc140caddae --- /dev/null +++ b/scripts/update-semconv-version.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +package_name="go.opentelemetry.io/otel/semconv" +version_regex="v[0-9]\.[0-9]\+\.[0-9]\+" + +latest_semconv_version=$( + curl -s https://pkg.go.dev/$package_name \ + | grep -oP 'data-id="v\d+\.\d+\.\d+"' \ + | sed -E 's/\"($version_regex)\"/v\1/' \ + | sort -Vr \ + | head -n 1 \ + | awk -F'"' '{print $2}' +) + +latest_package_string="$package_name/$latest_semconv_version" + +while IFS=: read -r file_name package_string; do + version_number=${package_string##*/} + + if [ "$version_number" != "$latest_semconv_version" ]; then + sed -i "s#$package_name/$version_regex#$latest_package_string#g" "$file_name" + { + printf "Source File: %-60s | Previous Semconv Version: %s | Updated Semconv Version: %s\n" "$file_name" "$version_number" "$latest_semconv_version" + } | column -t -s '|' + fi +done < <(find . -type f -name "*.go" -exec grep -o -H "$package_name/$version_regex" {} +)