Skip to content

Git commit sha metric#19123

Open
razinbouzar wants to merge 4 commits intoapache:masterfrom
razinbouzar:git-commit-sha-metric
Open

Git commit sha metric#19123
razinbouzar wants to merge 4 commits intoapache:masterfrom
razinbouzar:git-commit-sha-metric

Conversation

@razinbouzar
Copy link
Contributor

@razinbouzar razinbouzar commented Mar 10, 2026

Adding a git commit sha as an emitted metric for version tracking.

Fixes #XXXX.

Description

Fixed the bug ...

Renamed the class ...

Added a forbidden-apis entry ...

Release note


Key changed/added classes in this PR
  • MyFoo
  • OurBar
  • TheirBaz

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

Added a method to load git properties from the classpath and include the git commit SHA in emitted metrics.
Copy link
Contributor

@abhishekrb19 abhishekrb19 left a comment

Choose a reason for hiding this comment

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

Thanks @razinbouzar! It’s useful to have this to track service health across rolling deployments with the same version. Left some high-level thoughts.

  1. Please document the new dimension in metrics.md: https://druid.apache.org/docs/latest/operations/metrics/ (something like a high level info note would suffice)
  2. Once the new dimension is in, we can also add the same info to sys.servers table similar to #18542. This would provide a SQL-friendly way to verify that clusters are running the intended commit, version, etc.

Comment on lines +200 to +216
private static Map<String, String> loadGitProperties()
{
try (InputStream is = EmitterModule.class.getClassLoader().getResourceAsStream("git.properties")) {
if (is != null) {
Properties props = new Properties();
props.load(is);

// Convert Properties to Map<String, String>
Map<String, String> gitProperties = new HashMap<>();
for (String key : props.stringPropertyNames()) {
String value = props.getProperty(key);
if (value != null && !value.trim().isEmpty()) {
gitProperties.put(key, value.trim());
}
}

return gitProperties;
Copy link
Contributor

Choose a reason for hiding this comment

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

On the approach, I'm wondering whether using git.properties from the class loader vs using META-INF/MANIFEST.MF (produced by the JAR build) would be better.

Is the former coming from git-commit-id-maven-plugin: https://github.com/apache/druid/blob/master/pom.xml#L1878-L1903?

The latter should be available through https://github.com/apache/druid/blob/master/pom.xml#L1870:

Build-Revision: 1c2eb65...
Build-Version: 37.0.0-SNAPSHOT

Looks like version internally reads from the manifest as well: String version = getClass().getPackage().getImplementationVersion()

But those are standard properties, so we may want a small utility to read the Git SHA / build revision from the manifest, such as the Build-Revision property. I’ll also give it some thought.

} else {
// Fallback value when git properties are not available
extraServiceDimensions
.addBinding("gitSha")
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on naming: gitSha or buildRevision or something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants