Skip to content

Commit ea0cbdd

Browse files
authored
feat: log connector version and git revision (#21)
fixes #10
1 parent e62b8d8 commit ea0cbdd

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

connector/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@
116116
</execution>
117117
</executions>
118118
</plugin>
119+
<plugin>
120+
<groupId>pl.project13.maven</groupId>
121+
<artifactId>git-commit-id-plugin</artifactId>
122+
<version>4.9.10</version>
123+
<executions>
124+
<execution>
125+
<id>get-the-git-infos</id>
126+
<goals>
127+
<goal>revision</goal>
128+
</goals>
129+
</execution>
130+
</executions>
131+
<configuration>
132+
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
133+
<prefix>git</prefix>
134+
<generateGitPropertiesFile>true</generateGitPropertiesFile>
135+
<generateGitPropertiesFilename>${project.build.outputDirectory}/questdb_connector_version.properties</generateGitPropertiesFilename>
136+
<gitDescribe>
137+
<skip>false</skip>
138+
<always>false</always>
139+
<dirty>-dirty</dirty>
140+
</gitDescribe>
141+
</configuration>
142+
</plugin>
119143
<plugin>
120144
<groupId>io.confluent</groupId>
121145
<version>0.12.0</version>

connector/src/main/java/io/questdb/kafka/QuestDBSinkTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public String version() {
5151

5252
@Override
5353
public void start(Map<String, String> map) {
54+
log.info("Starting QuestDB sink task [version={}, commit={}]", VersionUtil.getVersion(), VersionUtil.getGitHash());
5455
this.config = new QuestDBSinkConnectorConfig(map);
5556
String timestampStringFields = config.getTimestampStringFields();
5657
if (timestampStringFields != null) {
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
package io.questdb.kafka;
22

3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.Properties;
6+
37
final class VersionUtil {
4-
static String getVersion() {
5-
try {
6-
return VersionUtil.class.getPackage().getImplementationVersion();
7-
} catch (Exception ex) {
8-
return "0.0.0.0";
8+
private static final String VERSION;
9+
private static final String GIT_HASH;
10+
private static final String UNKNOWN = "unknown";
11+
private static final String PROPERTIES_FILE = "questdb_connector_version.properties"; // keep in sync with pom.xml
12+
13+
static {
14+
Properties properties = new Properties();
15+
String version;
16+
String gitHash;
17+
try (InputStream is = VersionUtil.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE)){
18+
if (is == null) {
19+
version = UNKNOWN;
20+
gitHash = UNKNOWN;
21+
} else {
22+
properties.load(is);
23+
version = String.valueOf(properties.getOrDefault("git.build.version", UNKNOWN));
24+
gitHash = String.valueOf(properties.getOrDefault("git.commit.id.abbrev", UNKNOWN));
25+
}
26+
} catch (IOException e) {
27+
version = UNKNOWN;
28+
gitHash = UNKNOWN;
929
}
30+
VERSION = version;
31+
GIT_HASH = gitHash;
32+
}
33+
34+
static String getVersion() {
35+
return VERSION;
36+
}
37+
38+
static String getGitHash() {
39+
return GIT_HASH;
1040
}
1141
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.questdb.kafka;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class VersionUtilTest {
8+
// if these tests are failing then build the project with maven
9+
// maven build generates the questdb_connector_version.properties file
10+
11+
@Test
12+
public void testGetVersion() {
13+
String version = VersionUtil.getVersion();
14+
assertNotNull(version);
15+
assertNotEquals("unknown", version);
16+
assertFalse(version.isEmpty());
17+
}
18+
19+
@Test
20+
public void testGetGitHash() {
21+
String gitHash = VersionUtil.getGitHash();
22+
assertNotNull(gitHash);
23+
assertNotEquals("unknown", gitHash);
24+
assertFalse(gitHash.isEmpty());
25+
}
26+
}

0 commit comments

Comments
 (0)