Skip to content

Commit

Permalink
fix: report connector package version instead of kafka connect version (
Browse files Browse the repository at this point in the history
#266)

* fix: report connector package version instead of kafka connect version

* fix: lint
  • Loading branch information
HurSungYun authored Jun 18, 2024
1 parent a14a933 commit 33f2761
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 12 deletions.
31 changes: 31 additions & 0 deletions src/main/java/com/google/pubsub/kafka/common/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2023 Google Inc.
*
* Licensed 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 com.google.pubsub.kafka.common;

public class Version {
private static String version = "unknown";

static {
String implementationVersion = Version.class.getPackage().getImplementationVersion();
if (implementationVersion != null) {
version = implementationVersion;
}
}

public static String version() {
return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.pubsub.kafka.sink;

import com.google.pubsub.kafka.common.ConnectorUtils;
import com.google.pubsub.kafka.common.Version;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -25,7 +26,6 @@
import org.apache.kafka.common.config.ConfigDef.Importance;
import org.apache.kafka.common.config.ConfigDef.Type;
import org.apache.kafka.common.config.ConfigException;
import org.apache.kafka.common.utils.AppInfoParser;
import org.apache.kafka.connect.connector.Task;
import org.apache.kafka.connect.sink.SinkConnector;
import org.slf4j.Logger;
Expand Down Expand Up @@ -117,7 +117,7 @@ public void ensureValid(String name, Object o) {

@Override
public String version() {
return AppInfoParser.getVersion();
return Version.version();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.pubsub.kafka.common.ConnectorCredentialsProvider;
import com.google.pubsub.kafka.common.ConnectorUtils;
import com.google.pubsub.kafka.common.Version;
import com.google.pubsub.v1.GetSubscriptionRequest;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -31,7 +32,6 @@
import org.apache.kafka.common.config.ConfigDef.Importance;
import org.apache.kafka.common.config.ConfigDef.Type;
import org.apache.kafka.common.config.ConfigException;
import org.apache.kafka.common.utils.AppInfoParser;
import org.apache.kafka.connect.connector.Task;
import org.apache.kafka.connect.errors.ConnectException;
import org.apache.kafka.connect.source.SourceConnector;
Expand Down Expand Up @@ -130,7 +130,7 @@ public void ensureValid(String name, Object o) {

@Override
public String version() {
return AppInfoParser.getVersion();
return Version.version();
}

@Override
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/google/pubsublite/kafka/common/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2023 Google Inc.
*
* Licensed 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 com.google.pubsublite.kafka.common;

public class Version {
private static String version = "unknown";

static {
String implementationVersion = Version.class.getPackage().getImplementationVersion();
if (implementationVersion != null) {
version = implementationVersion;
}
}

public static String version() {
return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.google.pubsublite.kafka.sink;

import com.google.pubsublite.kafka.common.Version;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.kafka.common.config.ConfigDef;
import org.apache.kafka.common.utils.AppInfoParser;
import org.apache.kafka.connect.connector.Task;
import org.apache.kafka.connect.sink.SinkConnector;

Expand All @@ -28,7 +28,7 @@ public class PubSubLiteSinkConnector extends SinkConnector {

@Override
public String version() {
return AppInfoParser.getVersion();
return Version.version();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import javax.annotation.Nullable;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.utils.AppInfoParser;
import org.apache.kafka.connect.header.ConnectHeaders;
import org.apache.kafka.connect.header.Header;
import org.apache.kafka.connect.sink.SinkRecord;
Expand All @@ -54,7 +53,7 @@ public PubSubLiteSinkTask() {

@Override
public String version() {
return AppInfoParser.getVersion();
return new PubSubLiteSinkConnector().version();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.google.pubsublite.kafka.source;

import com.google.pubsublite.kafka.common.Version;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.kafka.common.config.ConfigDef;
import org.apache.kafka.common.utils.AppInfoParser;
import org.apache.kafka.connect.connector.Task;
import org.apache.kafka.connect.source.SourceConnector;

Expand All @@ -29,7 +29,7 @@ public class PubSubLiteSourceConnector extends SourceConnector {

@Override
public String version() {
return AppInfoParser.getVersion();
return Version.version();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.kafka.common.utils.AppInfoParser;
import org.apache.kafka.connect.source.SourceRecord;
import org.apache.kafka.connect.source.SourceTask;

Expand All @@ -39,7 +38,7 @@ public PubSubLiteSourceTask() {

@Override
public String version() {
return AppInfoParser.getVersion();
return new PubSubLiteSourceConnector().version();
}

@Override
Expand Down

0 comments on commit 33f2761

Please sign in to comment.