-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[MINOR] Publish HUDI version metrics as integers #17466
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
Open
prashantwason
wants to merge
1
commit into
apache:master
Choose a base branch
from
prashantwason:pw_oss_commit_porting_6
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+220
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| package org.apache.hudi.client; | ||
|
|
||
| import org.apache.hudi.HoodieVersion; | ||
| import org.apache.hudi.avro.HoodieAvroUtils; | ||
| import org.apache.hudi.avro.model.HoodieCleanMetadata; | ||
| import org.apache.hudi.avro.model.HoodieIndexCommitMetadata; | ||
|
|
@@ -175,6 +176,15 @@ public BaseHoodieWriteClient(HoodieEngineContext context, | |
| super(context, writeConfig, timelineService); | ||
| this.index = createIndex(writeConfig); | ||
| this.upgradeDowngradeHelper = upgradeDowngradeHelper; | ||
| if (config.isMetricsOn()) { | ||
| // report userName and hudi version | ||
| final String version = HoodieVersion.get(); | ||
| metrics.getMetrics().registerGauge(metrics.getMetricsName("userName", System.getProperty("user.name")), 1); | ||
| metrics.getMetrics().registerGauge(metrics.getMetricsName("version", StringUtils.isNullOrEmpty(version) ? "0.14.x" : version), 1); | ||
| metrics.getMetrics().registerGauge("version.major", HoodieVersion.majorAsInt()); | ||
| metrics.getMetrics().registerGauge("version.minor", HoodieVersion.minorAsInt()); | ||
| metrics.getMetrics().registerGauge("version.patch", HoodieVersion.patchAsInt()); | ||
| } | ||
|
Comment on lines
+179
to
+187
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the logic be put into |
||
| this.metrics.emitIndexTypeMetrics(config.getIndexType().ordinal()); | ||
| } | ||
|
|
||
|
|
||
143 changes: 143 additions & 0 deletions
143
hudi-common/src/main/java/org/apache/hudi/HoodieVersion.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.hudi; | ||
|
|
||
| import org.apache.hudi.common.util.StringUtils; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.util.Properties; | ||
|
|
||
| /** | ||
| * Exposes the semantic versioning (https://semver.org/) of HUDI code. | ||
| * | ||
| * HUDI versions are configured through maven and are formatted as <major>.<minor>.<patch>. Example: 0.12.2 or 0.12.3-snapshot | ||
| */ | ||
| public final class HoodieVersion { | ||
| private static String HOODIE_DEFAULT_VERSION = "0.14.x"; | ||
|
|
||
| public static final String HOODIE_WRITER_VERSION = "hudi_writer_version"; | ||
|
|
||
| /** | ||
| * Returns the complete version of HUDI code | ||
| * Example: 0.12.2 or 0.12.3-snapshot | ||
| */ | ||
| public static String get() { | ||
| String hudiPropertiesFilePath = "META-INF/maven/org.apache.hudi/hudi-common/pom.properties"; | ||
| try (InputStream inputStream = HoodieVersion.class.getClassLoader().getResourceAsStream(hudiPropertiesFilePath)) { | ||
| Properties properties = new Properties(); | ||
| if (inputStream != null) { | ||
| properties.load(inputStream); | ||
| // Access properties | ||
| return properties.getProperty("version"); | ||
| } | ||
| } catch (Exception ignored) { | ||
| // Ignoring the exception as there is as fallback to default version | ||
| } | ||
| return HOODIE_DEFAULT_VERSION; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the major version of HUDI code | ||
| * Example: 0 for 0.12.2 | ||
| */ | ||
| public static String major() { | ||
| return getVersion(1); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the minor version of HUDI code | ||
| * Example: 0.12 for 0.12.2 | ||
| */ | ||
| public static String minor() { | ||
| return getVersion(2); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the patch version of HUDI code | ||
| * Example: 0.12.2 for 0.12.2, 0.12.3-SNAPSHOT for 0.12.3-SNAPSHOT | ||
| */ | ||
| public static String patch() { | ||
| return getVersion(3); | ||
| } | ||
|
|
||
| private static String getVersion(int allowedDotCount) { | ||
| return getSubVersion(get(), allowedDotCount); | ||
| } | ||
|
|
||
| private static String getSubVersion(String version, int allowedDotCount) { | ||
| if (allowedDotCount == 1) { | ||
| int index = version.indexOf('.'); | ||
| return index == -1 ? version : version.substring(0, index); | ||
| } | ||
| return getSubVersion(version.substring(version.indexOf('.') + 1), allowedDotCount - 1); | ||
| } | ||
|
|
||
| protected static void setVersionOverride(String version) { | ||
| HOODIE_DEFAULT_VERSION = version; | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("hoodie version=" + get()); | ||
| System.out.println(" major=" + major()); | ||
| System.out.println(" minor=" + minor()); | ||
| System.out.println(" patch=" + patch()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the major version of HUDI code as an integer | ||
| */ | ||
| public static int majorAsInt() { | ||
| return toInt(major()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the minor version of HUDI code as an integer | ||
| */ | ||
| public static int minorAsInt() { | ||
| return toInt(minor()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the patch version of HUDI code as an integer | ||
| */ | ||
| public static int patchAsInt() { | ||
| return toInt(patch()); | ||
| } | ||
|
|
||
| /** | ||
| * Convert the string to an integer ignoring any non-numeric characters towards the end of the string. | ||
| * @param str The string to convert. | ||
| * @return The integer value of the string. Returns 0 if the string is null, empty or does not have any numeric values. | ||
| */ | ||
| private static int toInt(String str) { | ||
| if (StringUtils.isNullOrEmpty(str)) { | ||
| return 0; | ||
| } | ||
|
|
||
| // Find the number of digits in the starting of the string. | ||
| int i = 0; | ||
| while (i < str.length() && Character.isDigit(str.charAt(i))) { | ||
| i++; | ||
| } | ||
| if (i > 0) { | ||
| return Integer.parseInt(str.substring(0, i)); | ||
| } | ||
| return 0; | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
hudi-common/src/test/java/org/apache/hudi/TestHoodieVersion.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.hudi; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class TestHoodieVersion { | ||
| @Test | ||
| public void testVersion() { | ||
|
|
||
| HoodieVersion.setVersionOverride("0.12.2"); | ||
| assertEquals(HoodieVersion.get(), "0.12.2"); | ||
| assertEquals(HoodieVersion.major(), "0"); | ||
| assertEquals(HoodieVersion.minor(), "12"); | ||
| assertEquals(HoodieVersion.patch(), "2"); | ||
| assertEquals(HoodieVersion.majorAsInt(), 0); | ||
| assertEquals(HoodieVersion.minorAsInt(), 12); | ||
| assertEquals(HoodieVersion.patchAsInt(), 2); | ||
|
|
||
| HoodieVersion.setVersionOverride("0.12.2-spark3"); | ||
| assertEquals(HoodieVersion.get(), "0.12.2-spark3"); | ||
| assertEquals(HoodieVersion.major(), "0"); | ||
| assertEquals(HoodieVersion.minor(), "12"); | ||
| assertEquals(HoodieVersion.patch(), "2-spark3"); | ||
| assertEquals(HoodieVersion.majorAsInt(), 0); | ||
| assertEquals(HoodieVersion.minorAsInt(), 12); | ||
| assertEquals(HoodieVersion.patchAsInt(), 2); | ||
|
|
||
| HoodieVersion.setVersionOverride("1.2.spark3"); | ||
| assertEquals(HoodieVersion.majorAsInt(), 1); | ||
| assertEquals(HoodieVersion.minorAsInt(), 2); | ||
| assertEquals(HoodieVersion.patchAsInt(), 0); | ||
|
|
||
| HoodieVersion.setVersionOverride("1.2.34.35"); | ||
| assertEquals(HoodieVersion.majorAsInt(), 1); | ||
| assertEquals(HoodieVersion.minorAsInt(), 2); | ||
| assertEquals(HoodieVersion.patchAsInt(), 34); | ||
|
|
||
| HoodieVersion.setVersionOverride("1.2.34-spark-5"); | ||
| assertEquals(HoodieVersion.majorAsInt(), 1); | ||
| assertEquals(HoodieVersion.minorAsInt(), 2); | ||
| assertEquals(HoodieVersion.patchAsInt(), 34); | ||
|
|
||
| HoodieVersion.setVersionOverride("a.b.c"); | ||
| assertEquals(HoodieVersion.majorAsInt(), 0); | ||
| assertEquals(HoodieVersion.minorAsInt(), 0); | ||
| assertEquals(HoodieVersion.patchAsInt(), 0); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these still needed if the full
versionis published?