Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shell script to ensure consistent version of OTEL semconv #4652

Merged
merged 4 commits into from
Aug 14, 2023
Merged

Add shell script to ensure consistent version of OTEL semconv #4652

merged 4 commits into from
Aug 14, 2023

Conversation

perhapsmaple
Copy link
Contributor

@perhapsmaple perhapsmaple commented Aug 12, 2023

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

Checklist

@perhapsmaple perhapsmaple requested a review from a team as a code owner August 12, 2023 17:02
@Mayhul-Jindal
Copy link

@perhapsmaple did you get any error while running make install-tools ?

@perhapsmaple
Copy link
Contributor Author

@Mayhul-Jindal I had no errors while running make. Although, install-tools did not download the tparallel module on my machine

@perhapsmaple
Copy link
Contributor Author

perhapsmaple commented Aug 12, 2023

@yurishkuro I wanted to know if there was any way other than using curl to determine the latest version of semconv available. The go list command only seems to work for the go.opentelemetry.io/otel package. I would be willing to work on another script that updates all references to the latest version of semconv.

@codecov
Copy link

codecov bot commented Aug 12, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01% ⚠️

Comparison is base (941c115) 97.04% compared to head (efe85f3) 97.04%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4652      +/-   ##
==========================================
- Coverage   97.04%   97.04%   -0.01%     
==========================================
  Files         301      301              
  Lines       17878    17878              
==========================================
- Hits        17350    17349       -1     
- Misses        423      424       +1     
  Partials      105      105              
Flag Coverage Δ
unittests 97.04% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -10,12 +10,12 @@ done < <(find . -type f -name "*.go" -exec grep -o -H "go.opentelemetry.io/otel/
semconv_versions=($(printf "%s\n" "${semconv_map[@]}" | sort -u))

if [ ${#semconv_versions[@]} -gt 1 ]; then
echo "Error: semconv version mismatch detected"
echo "Error: semconv version mismatch detected. Run ./scripts/update-semconv-version.sh to update semconv to latest version."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend printing "Run <script>" line at the end of the output, after the listing of files.

declare -A semconv_map

while IFS=: read -r file_name package_string; do
version_number=$(echo "$package_string" | grep -o -E "v1\.[0-9]+\.[0-9]+")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version_number=$(echo "$package_string" | grep -o -E "v1\.[0-9]+\.[0-9]+")
version_number=$(echo "$package_string" | grep -o -E "v[0-9]\.[0-9]+\.[0-9]+")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, this regex is used more then once, let's move it to a variable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, why do you need this grep here in the first place, isn't it guaranteed to match because of L8?

echo "Error: semconv version mismatch detected. Run ./scripts/update-semconv-version.sh to update semconv to latest version."
{
for key in "${!semconv_map[@]}"; do
printf "Source File: %-30s | Semconv Version: %s\n" "$key" "${semconv_map[$key]}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printf "Source File: %-30s | Semconv Version: %s\n" "$key" "${semconv_map[$key]}"
printf "Source File: %-50s | Semconv Version: %s\n" "$key" "${semconv_map[$key]}"

30 may not be long enough

- Introduced variables for package name and regex expression
- Replaced unnecessary grep to extract version number with bash parameter expansion
- Moved print "Run <script>" to the end of the output and addressed alignment

Signed-off-by: Harish Shan <[email protected]>
@perhapsmaple
Copy link
Contributor Author

Hi @yurishkuro ,I have addressed all of your initial comments. Let me know if there are any further changes required

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@yurishkuro yurishkuro merged commit 07c34ee into jaegertracing:main Aug 14, 2023
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ci] Add CI check to ensure consistent version of OTEL semconv
3 participants