Skip to content
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

feat: log connector version and git revision #21

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading