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 git version on build in logs, OTEL metadata and API #873

Merged
merged 2 commits into from
Feb 25, 2025

Conversation

apognu
Copy link
Contributor

@apognu apognu commented Feb 25, 2025

This PR adds an endpoint to retrieve the running version of the API. It is a bit more involved than expected:

  • Version defaults to dev
  • If specified during build, it now uses git describe --tags, which will render:
    • v0.36.1 if on a tag
    • v0.36.1-2-g123456 if not (the latest tag, the number of commit since, and the sha of the commit), useful for staging
  • It logs the version (still need to add logs to the other components)
  • It sets the version in OTEL and Sentry (@Pascal-Delange, do we want this?)
  • It adds a /version endpoint for the frontend to use

@Pascal-Delange, right now the endpoint is unauthenticated, which could be considered a security issue (leaking the version of the software). But we want to display it on the login screen as well, which would require it being unauthenticated. Also, the version would be leaked by the frontend code itself anyway, so it would not be worse. Just pointing it out.

Also @Pascal-Delange, this touches the deploy script (through the Dockerfile, so I want to check I did not miss a usage of the initial version variable that I changed).

@apognu apognu added enhancement New feature or request go Pull requests that update Go code labels Feb 25, 2025
@apognu apognu self-assigned this Feb 25, 2025
@apognu apognu force-pushed the feat/version-api branch 2 times, most recently from 06914d9 to 17a1a19 Compare February 25, 2025 11:35
@apognu apognu changed the title Add git version on build in logs and OTEL metadata. Add git version on build in logs, OTEL metadata and API Feb 25, 2025
@apognu apognu marked this pull request as ready for review February 25, 2025 11:54
Copy link
Contributor

@Pascal-Delange Pascal-Delange left a comment

Choose a reason for hiding this comment

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

👍 but the code to actually read the env var is missing, no ?
No worries about the unauthenticated endpoint, there is already another one (the liveness one)

@apognu
Copy link
Contributor Author

apognu commented Feb 25, 2025

There is no env var, it uses a build option that sets a global variable during compilation (-X main.apiVersion=)

@Pascal-Delange
Copy link
Contributor

Oh, got it.
Didn't know you could set the value of a variable in a package like this from a build option 😅
Then that's cool, but let's maybe add a small comment where the variable is defined to explain where its value comes from ? Otherwise it's a bit magical if you don't know this option.

@@ -9,6 +9,11 @@ import (
"github.com/checkmarble/marble-backend/utils"
)

// Static variable set at compilation-time through linker flags.
//
// $ go build -ldflags '-X main.apiVersion=v0.10.0' .
Copy link
Contributor

Choose a reason for hiding this comment

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

🙏

@apognu apognu merged commit f49c40f into main Feb 25, 2025
3 checks passed
@apognu apognu deleted the feat/version-api branch February 25, 2025 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants