-
Notifications
You must be signed in to change notification settings - Fork 12
feat: add telemetry support #63
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
020d326
feat: add telemetry support
ali-ince c7a829c
refactor: move strategy list to the user agent string
ali-ince 4cf3681
fix: update user agent string formatting
ali-ince b0dc5b8
refactor: address review comments
ali-ince fe58c55
Merge branch 'main' into feat-telemetry
ali-ince File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
common/src/main/kotlin/org/neo4j/connectors/kafka/utils/Telemetry.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * Copyright (c) "Neo4j" | ||
| * Neo4j Sweden AB [http://neo4j.com] | ||
| * | ||
| * 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 org.neo4j.connectors.kafka.utils | ||
|
|
||
| import org.apache.kafka.common.utils.AppInfoParser | ||
| import org.neo4j.connectors.kafka.configuration.Neo4jConfiguration | ||
| import org.neo4j.connectors.kafka.configuration.helpers.VersionUtil | ||
| import org.neo4j.driver.Config | ||
|
|
||
| interface EnvironmentProvider { | ||
| fun get(env: String): String? | ||
| } | ||
|
|
||
| object Telemetry { | ||
| internal const val CONFLUENT_ENV: String = "CONFLUENT_ENV" | ||
| internal const val CONFLUENT_ENV_VALUE: String = "CCLOUD_CUSTOM_CONNECTOR" | ||
|
|
||
| private object SystemEnvironmentProvider : EnvironmentProvider { | ||
| override fun get(env: String): String? { | ||
| return System.getenv(env) | ||
| } | ||
| } | ||
|
|
||
| fun userAgent( | ||
| type: String, | ||
| legacy: Boolean = false, | ||
| comment: String = "", | ||
| provider: EnvironmentProvider = SystemEnvironmentProvider | ||
| ): String { | ||
| return String.format( | ||
| "%s %s (%s) %s %s", | ||
| connectorInformation( | ||
| type, legacy, VersionUtil.version(Neo4jConfiguration::class.java), comment, provider), | ||
| kafkaConnectInformation(), | ||
| platform(), | ||
| neo4jDriverVersion(), | ||
| jreInformation(), | ||
| ) | ||
| } | ||
|
|
||
| private fun runningInConfluentCloud( | ||
| provider: EnvironmentProvider = SystemEnvironmentProvider | ||
| ): Boolean { | ||
| val value = provider.get(CONFLUENT_ENV) | ||
| if (value.isNullOrEmpty()) { | ||
| return false | ||
| } | ||
| return value.contentEquals(CONFLUENT_ENV_VALUE, true) | ||
| } | ||
|
|
||
| internal fun connectorInformation( | ||
| type: String, | ||
| legacy: Boolean, | ||
| version: String = "", | ||
| comment: String = "", | ||
| provider: EnvironmentProvider = SystemEnvironmentProvider | ||
| ): String { | ||
| return String.format( | ||
| "%s-%s%s%s", | ||
| if (runningInConfluentCloud(provider)) "confluent-cloud" else "kafka", | ||
| if (legacy) "legacy-$type" else type, | ||
| if (version.isEmpty()) "" else "/$version", | ||
| if (comment.isEmpty()) "" else " ($comment)") | ||
| } | ||
|
|
||
| internal fun kafkaConnectInformation(): String { | ||
| return String.format("kafka-connect/%s", AppInfoParser.getVersion()) | ||
| } | ||
|
|
||
| internal fun platform(): String { | ||
| return String.format( | ||
| "%s; %s; %s", | ||
| System.getProperty("os.name"), | ||
| System.getProperty("os.version"), | ||
| System.getProperty("os.arch"), | ||
| ) | ||
| } | ||
|
|
||
| internal fun neo4jDriverVersion(): String { | ||
| return Config.defaultConfig().userAgent() | ||
| } | ||
|
|
||
| internal fun jreInformation(): String { | ||
| // this format loosely follows the Java driver's Bolt Agent format | ||
| return String.format( | ||
| "Java/%s (%s; %s; %s)", | ||
| System.getProperty("java.version"), | ||
| System.getProperty("java.vm.vendor"), | ||
| System.getProperty("java.vm.name"), | ||
| System.getProperty("java.vm.version"), | ||
| ) | ||
| } | ||
| } | ||
113 changes: 113 additions & 0 deletions
113
common/src/test/kotlin/org/neo4j/connectors/kafka/utils/TelemetryTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * Copyright (c) "Neo4j" | ||
| * Neo4j Sweden AB [http://neo4j.com] | ||
| * | ||
| * 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 org.neo4j.connectors.kafka.utils | ||
|
|
||
| import io.kotest.matchers.shouldBe | ||
| import io.kotest.matchers.string.shouldStartWith | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.condition.EnabledOnJre | ||
| import org.junit.jupiter.api.condition.EnabledOnOs | ||
| import org.junit.jupiter.api.condition.JRE | ||
| import org.junit.jupiter.api.condition.OS | ||
| import org.mockito.kotlin.doReturn | ||
| import org.mockito.kotlin.mock | ||
| import org.neo4j.connectors.kafka.utils.Telemetry.CONFLUENT_ENV | ||
| import org.neo4j.connectors.kafka.utils.Telemetry.CONFLUENT_ENV_VALUE | ||
| import org.neo4j.connectors.kafka.utils.Telemetry.connectorInformation | ||
| import org.neo4j.connectors.kafka.utils.Telemetry.jreInformation | ||
| import org.neo4j.connectors.kafka.utils.Telemetry.neo4jDriverVersion | ||
| import org.neo4j.connectors.kafka.utils.Telemetry.platform | ||
|
|
||
| class TelemetryTest { | ||
|
|
||
| @Test | ||
| fun `should return driver version`() { | ||
| neo4jDriverVersion() shouldStartWith "neo4j-java" | ||
| } | ||
|
|
||
| @Test | ||
| @EnabledOnJre(JRE.JAVA_11) | ||
| fun `should return jre information on jre 11`() { | ||
| jreInformation() shouldStartWith "Java/11" | ||
| } | ||
|
|
||
| @Test | ||
| @EnabledOnJre(JRE.JAVA_17) | ||
| fun `should return jre information on jre 17`() { | ||
| jreInformation() shouldStartWith "Java/17" | ||
| } | ||
|
|
||
| @Test | ||
| @EnabledOnJre(JRE.JAVA_21) | ||
| fun `should return jre information on jre 21`() { | ||
| jreInformation() shouldStartWith "Java/21" | ||
| } | ||
|
|
||
| @Test | ||
| @EnabledOnOs(OS.MAC) | ||
| fun `should return platform`() { | ||
| platform() shouldStartWith "Mac OS X" | ||
| } | ||
|
|
||
| @Test | ||
| fun `should return connector information with kafka`() { | ||
| val provider = mock<EnvironmentProvider> { on { get(CONFLUENT_ENV) } doReturn null } | ||
|
|
||
| connectorInformation("sink", false, "", "", provider) shouldBe "kafka-sink" | ||
| connectorInformation("sink", false, "5.1.0", "", provider) shouldBe "kafka-sink/5.1.0" | ||
| connectorInformation("source", false, "", "", provider) shouldBe "kafka-source" | ||
| connectorInformation("source", false, "5.1.0", "", provider) shouldBe "kafka-source/5.1.0" | ||
| connectorInformation("sink", true, "", "", provider) shouldBe "kafka-legacy-sink" | ||
| connectorInformation("source", true, "", "", provider) shouldBe "kafka-legacy-source" | ||
| connectorInformation("sink", false, "", "cypher; node-pattern", provider) shouldBe | ||
| "kafka-sink (cypher; node-pattern)" | ||
| connectorInformation("sink", false, "5.1.0", "cypher; node-pattern", provider) shouldBe | ||
| "kafka-sink/5.1.0 (cypher; node-pattern)" | ||
| connectorInformation("source", false, "", "cdc", provider) shouldBe "kafka-source (cdc)" | ||
| connectorInformation("source", false, "5.1.0", "cdc", provider) shouldBe | ||
| "kafka-source/5.1.0 (cdc)" | ||
| connectorInformation("sink", true, "", "cypher", provider) shouldBe "kafka-legacy-sink (cypher)" | ||
| connectorInformation("source", true, "", "query", provider) shouldBe | ||
| "kafka-legacy-source (query)" | ||
| } | ||
|
|
||
| @Test | ||
| fun `should return connector information with confluent-cloud`() { | ||
| val provider = | ||
| mock<EnvironmentProvider> { on { get(CONFLUENT_ENV) } doReturn CONFLUENT_ENV_VALUE } | ||
|
|
||
| connectorInformation("sink", false, "", "", provider) shouldBe "confluent-cloud-sink" | ||
| connectorInformation("sink", false, "5.1.0", "", provider) shouldBe "confluent-cloud-sink/5.1.0" | ||
| connectorInformation("source", false, "", "", provider) shouldBe "confluent-cloud-source" | ||
| connectorInformation("source", false, "5.1.0", "", provider) shouldBe | ||
| "confluent-cloud-source/5.1.0" | ||
| connectorInformation("sink", true, "", "", provider) shouldBe "confluent-cloud-legacy-sink" | ||
| connectorInformation("source", true, "", "", provider) shouldBe "confluent-cloud-legacy-source" | ||
| connectorInformation("sink", false, "", "cypher; node-pattern", provider) shouldBe | ||
| "confluent-cloud-sink (cypher; node-pattern)" | ||
| connectorInformation("sink", false, "5.1.0", "cypher; node-pattern", provider) shouldBe | ||
| "confluent-cloud-sink/5.1.0 (cypher; node-pattern)" | ||
| connectorInformation("source", false, "", "cdc", provider) shouldBe | ||
| "confluent-cloud-source (cdc)" | ||
| connectorInformation("source", false, "5.1.0", "cdc", provider) shouldBe | ||
| "confluent-cloud-source/5.1.0 (cdc)" | ||
| connectorInformation("sink", true, "", "cypher", provider) shouldBe | ||
| "confluent-cloud-legacy-sink (cypher)" | ||
| connectorInformation("source", true, "", "query", provider) shouldBe | ||
| "confluent-cloud-legacy-source (query)" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.