Skip to content

Commit

Permalink
[Feature] use git-commit-id-plugin to get git information at runtime (S…
Browse files Browse the repository at this point in the history
…tarRocks#213)

[Feature] use git-commit-id-plugin to get git information at runtime

Signed-off-by: PengFei Li <lpengfei2016@gmail.com>
  • Loading branch information
banmoy committed Apr 21, 2023
1 parent 8b58748 commit 189a266
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 34 deletions.
30 changes: 30 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,36 @@ limitations under the License.
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.2</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<phase>initialize</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/starrocks-connector-git.properties</generateGitPropertiesFilename>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.time$</includeOnlyProperty>
<includeOnlyProperty>^git.build.version$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.abbrev$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.time$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.user.email$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.user.name$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.message.full$</includeOnlyProperty>
</includeOnlyProperties>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.starrocks.connector.flink.row.sink.StarRocksIRowTransformer;
import com.starrocks.connector.flink.row.sink.StarRocksISerializer;
import com.starrocks.connector.flink.row.sink.StarRocksSerializerFactory;
import com.starrocks.connector.flink.tools.EnvUtils;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.alter.Alter;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void open(Configuration parameters) throws Exception {
}
sinkManager.startScheduler();
sinkManager.startAsyncFlushing();
LOG.info("Open sink function");
LOG.info("Open sink function. {}", EnvUtils.getGitInformation());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.starrocks.connector.flink.row.sink.StarRocksISerializer;
import com.starrocks.connector.flink.row.sink.StarRocksSerializerFactory;
import com.starrocks.connector.flink.table.data.StarRocksRowData;
import com.starrocks.connector.flink.tools.EnvUtils;
import com.starrocks.data.load.stream.StreamLoadSnapshot;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
Expand Down Expand Up @@ -170,7 +171,7 @@ public void open(Configuration parameters) throws Exception {
rowTransformer.setRuntimeContext(getRuntimeContext());
}
notifyCheckpointComplete(Long.MAX_VALUE);
log.info("Open sink function v2");
log.info("Open sink function v2. {}", EnvUtils.getGitInformation());
}

public void finish() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.starrocks.connector.flink.table.sink;

import com.starrocks.connector.flink.tools.SRFCUtils;
import com.starrocks.connector.flink.tools.EnvUtils;
import com.starrocks.data.load.stream.StreamLoadSnapshot;

import java.io.Serializable;
Expand All @@ -13,7 +13,7 @@ public class StarrocksSnapshotState implements Serializable {

public static StarrocksSnapshotState of(Map<Long, List<StreamLoadSnapshot>> data) {
StarrocksSnapshotState starrocksSnapshotState = new StarrocksSnapshotState();
starrocksSnapshotState.version = SRFCUtils.getSRFCVersion();
starrocksSnapshotState.version = EnvUtils.getSRFCVersion();
starrocksSnapshotState.data = data;
return starrocksSnapshotState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.starrocks.connector.flink.table.source.struct.QueryBeXTablets;
import com.starrocks.connector.flink.table.source.struct.QueryInfo;
import com.starrocks.connector.flink.table.source.struct.SelectColumn;

import com.starrocks.connector.flink.tools.EnvUtils;
import org.apache.flink.table.data.GenericRowData;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.functions.FunctionContext;
Expand Down Expand Up @@ -73,6 +73,7 @@ public StarRocksDynamicLookupFunction(StarRocksSourceOptions sourceOptions,
@Override
public void open(FunctionContext context) throws Exception {
super.open(context);
LOG.info("Open lookup function. {}", EnvUtils.getGitInformation());
}

public void eval(Object... keys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.starrocks.connector.flink.table.source.struct.QueryBeXTablets;
import com.starrocks.connector.flink.table.source.struct.QueryInfo;
import com.starrocks.connector.flink.table.source.struct.SelectColumn;
import com.starrocks.connector.flink.tools.EnvUtils;
import org.apache.flink.api.common.typeinfo.TypeHint;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
Expand Down Expand Up @@ -151,6 +152,7 @@ public void open(Configuration parameters) throws Exception {
this.dataReaderList.add(beReader);
});
}
LOG.info("Open source function. {}", EnvUtils.getGitInformation());
}

@Override
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/com/starrocks/connector/flink/tools/EnvUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.starrocks.connector.flink.tools;

import org.apache.flink.runtime.util.EnvironmentInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class EnvUtils {

private static class SRFCPropertiesHolder {

private static final Logger logger = LoggerFactory.getLogger(SRFCPropertiesHolder.class);
private static final Properties instance = loadProperties();
public static Properties loadProperties() {
Properties props = new Properties();
try {
props.load(SRFCPropertiesHolder.class.getClassLoader().getResourceAsStream("srfc.properties"));
} catch (IOException e) {
logger.warn("load srfc properties failed.", e);
}
return props;
}
}

public static String getSRFCVersion() {
return SRFCPropertiesHolder.instance.getProperty("srfc.version", "");
}

private static final class GitInformation {

private static final Logger LOG = LoggerFactory.getLogger(GitInformation.class);
private static final String PROP_FILE = "starrocks-connector-git.properties";
private static final String UNKNOWN = "unknown";

private static final GitInformation INSTANCE = new GitInformation();

private String gitBuildTime = UNKNOWN;
private String gitCommitId = UNKNOWN;
private String gitCommitIdAbbrev = UNKNOWN;
private String gitCommitTime = UNKNOWN;

private String getProperty(Properties properties, String key, String defaultValue) {
String value = properties.getProperty(key);
if (value == null || value.charAt(0) == '$') {
return defaultValue;
}
return value;
}

public GitInformation() {
ClassLoader classLoader = EnvironmentInformation.class.getClassLoader();
try (InputStream propFile = classLoader.getResourceAsStream(PROP_FILE)) {
if (propFile != null) {
Properties properties = new Properties();
properties.load(propFile);
gitBuildTime = getProperty(properties, "git.build.time", UNKNOWN);
gitCommitId = getProperty(properties, "git.commit.id", UNKNOWN);
gitCommitIdAbbrev = getProperty(properties, "git.commit.id.abbrev", UNKNOWN);
gitCommitTime = getProperty(properties, "git.commit.time", UNKNOWN);
}
} catch (Exception e) {
LOG.warn("Can't load git information, exception message: {}", e.getMessage());
}
}

public String getGitBuildTime() {
return gitBuildTime;
}

public String getGitCommitId() {
return gitCommitId;
}

public String getGitCommitIdAbbrev() {
return gitCommitIdAbbrev;
}

public String getGitCommitTime() {
return gitCommitTime;
}

@Override
public String toString() {
return "GitInformation{" +
"gitBuildTime='" + gitBuildTime + '\'' +
", gitCommitId='" + gitCommitId + '\'' +
", gitCommitIdAbbrev='" + gitCommitIdAbbrev + '\'' +
", gitCommitTime='" + gitCommitTime + '\'' +
'}';
}
}

public static GitInformation getGitInformation() {
return GitInformation.INSTANCE;
}
}
29 changes: 0 additions & 29 deletions src/main/java/com/starrocks/connector/flink/tools/SRFCUtils.java

This file was deleted.

0 comments on commit 189a266

Please sign in to comment.