Skip to content

Commit

Permalink
feat: log connector version and git revision
Browse files Browse the repository at this point in the history
fixes #10
  • Loading branch information
jerrinot committed May 23, 2024
1 parent e62b8d8 commit 35288df
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 5 deletions.
24 changes: 24 additions & 0 deletions connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.9.10</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<prefix>git</prefix>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/questdb_connector_version.properties</generateGitPropertiesFilename>
<gitDescribe>
<skip>false</skip>
<always>false</always>
<dirty>-dirty</dirty>
</gitDescribe>
</configuration>
</plugin>
<plugin>
<groupId>io.confluent</groupId>
<version>0.12.0</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public String version() {

@Override
public void start(Map<String, String> map) {
log.info("Starting QuestDB sink task [version={}, commit={}]", VersionUtil.getVersion(), VersionUtil.getGitHash());
this.config = new QuestDBSinkConnectorConfig(map);
String timestampStringFields = config.getTimestampStringFields();
if (timestampStringFields != null) {
Expand Down
40 changes: 35 additions & 5 deletions connector/src/main/java/io/questdb/kafka/VersionUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
package io.questdb.kafka;

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

final class VersionUtil {
static String getVersion() {
try {
return VersionUtil.class.getPackage().getImplementationVersion();
} catch (Exception ex) {
return "0.0.0.0";
private static final String VERSION;
private static final String GIT_HASH;
private static final String UNKNOWN = "unknown";
private static final String PROPERTIES_FILE = "questdb_connector_version.properties"; // keep in sync with pom.xml

static {
Properties properties = new Properties();
String version;
String gitHash;
try (InputStream is = VersionUtil.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE)){
if (is == null) {
version = UNKNOWN;
gitHash = UNKNOWN;
} else {
properties.load(is);
version = String.valueOf(properties.getOrDefault("git.build.version", UNKNOWN));
gitHash = String.valueOf(properties.getOrDefault("git.commit.id.abbrev", UNKNOWN));
}
} catch (IOException e) {
version = UNKNOWN;
gitHash = UNKNOWN;
}
VERSION = version;
GIT_HASH = gitHash;
}

static String getVersion() {
return VERSION;
}

static String getGitHash() {
return GIT_HASH;
}
}
26 changes: 26 additions & 0 deletions connector/src/test/java/io/questdb/kafka/VersionUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.questdb.kafka;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class VersionUtilTest {
// if these tests are failing then build the project with maven
// maven build generates the questdb_connector_version.properties file

@Test
public void testGetVersion() {
String version = VersionUtil.getVersion();
assertNotNull(version);
assertNotEquals("unknown", version);
assertFalse(version.isEmpty());
}

@Test
public void testGetGitHash() {
String gitHash = VersionUtil.getGitHash();
assertNotNull(gitHash);
assertNotEquals("unknown", gitHash);
assertFalse(gitHash.isEmpty());
}
}

0 comments on commit 35288df

Please sign in to comment.