-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add datadog for postgres source (#5088)
Integrate postgres source Datadog APM traces.
- Loading branch information
1 parent
c465c54
commit 1346fb9
Showing
9 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
96 changes: 96 additions & 0 deletions
96
...commons-worker/src/main/java/io/airbyte/workers/helper/ConnectorDatadogSupportHelper.java
This file contains 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,96 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.helper; | ||
|
||
import com.google.api.client.util.Preconditions; | ||
import io.airbyte.commons.version.AirbyteVersion; | ||
import io.airbyte.config.EnvConfigs; | ||
import io.airbyte.workers.WorkerConstants; | ||
import io.fabric8.kubernetes.api.model.EnvVar; | ||
import io.micrometer.common.util.StringUtils; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
|
||
/** | ||
* Utility class for Connector level Datadog support helper. | ||
*/ | ||
public class ConnectorDatadogSupportHelper { | ||
|
||
private static final String JAVA_OPTS = "JAVA_OPTS"; | ||
private static final String DD_SERVICE = "DD_SERVICE"; | ||
private static final String DD_VERSION = "DD_VERSION"; | ||
|
||
/** | ||
* addServerNameAndVersionToEnvVars. | ||
* | ||
* @param imageNameAndVersion ConnectorNameAndVersion record. | ||
* @param envVars List of environment variables. | ||
*/ | ||
public void addServerNameAndVersionToEnvVars(final String imageNameAndVersion, final List<EnvVar> envVars) { | ||
Preconditions.checkNotNull(imageNameAndVersion); | ||
Preconditions.checkNotNull(envVars); | ||
|
||
final Optional<ImmutablePair<String, AirbyteVersion>> imageNameVersionPair = extractAirbyteVersionFromImageName(imageNameAndVersion, ":"); | ||
if (imageNameVersionPair.isPresent()) { | ||
envVars.add(new EnvVar(DD_SERVICE, imageNameVersionPair.get().left, null)); | ||
envVars.add(new EnvVar(DD_VERSION, imageNameVersionPair.get().right.serialize(), null)); | ||
} | ||
} | ||
|
||
/** | ||
* getImageNameAndVersion. | ||
* | ||
* @param imageName image name in string format. | ||
* @param delimiter delimiter seperating connector image name and version. | ||
* @return ConnectorNameAndVersion Parsed ConnectorNameAndVersion record. | ||
*/ | ||
public Optional<ImmutablePair<String, AirbyteVersion>> extractAirbyteVersionFromImageName(final String imageName, final String delimiter) { | ||
Preconditions.checkNotNull(imageName); | ||
Preconditions.checkNotNull(delimiter); | ||
|
||
final String[] imageNameAndVersion = imageName.split(delimiter); | ||
final int expectedCount = 2; | ||
if (imageNameAndVersion.length == expectedCount && StringUtils.isNotEmpty(imageNameAndVersion[0])) { | ||
return Optional.of(ImmutablePair.of(imageNameAndVersion[0], new AirbyteVersion(imageNameAndVersion[1]))); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
/** | ||
* addDatadogVars. | ||
* | ||
* @param envVars List of environment variables. | ||
*/ | ||
public void addDatadogVars(final List<EnvVar> envVars) { | ||
envVars.add(new EnvVar(JAVA_OPTS, WorkerConstants.DD_ENV_VAR, null)); | ||
|
||
if (System.getenv(EnvConfigs.DD_AGENT_HOST) != null) { | ||
envVars.add(new EnvVar(EnvConfigs.DD_AGENT_HOST, System.getenv(EnvConfigs.DD_AGENT_HOST), null)); | ||
} | ||
if (System.getenv(EnvConfigs.DD_DOGSTATSD_PORT) != null) { | ||
envVars.add(new EnvVar(EnvConfigs.DD_DOGSTATSD_PORT, System.getenv(EnvConfigs.DD_DOGSTATSD_PORT), null)); | ||
} | ||
} | ||
|
||
/** | ||
* Utility function to check if connector image supports Datadog. | ||
* | ||
* @param firstConnectorVersionWithDatadog image and version when Datadog support was first added. | ||
* @param currentConnectorVersion current image and version number | ||
* @return True if current image version has Datadog support. | ||
*/ | ||
public boolean connectorVersionCompare(final String firstConnectorVersionWithDatadog, final String currentConnectorVersion) { | ||
final Optional<ImmutablePair<String, AirbyteVersion>> firstSupportedVersion = | ||
extractAirbyteVersionFromImageName(firstConnectorVersionWithDatadog, "="); | ||
final Optional<ImmutablePair<String, AirbyteVersion>> currentVersion = extractAirbyteVersionFromImageName(currentConnectorVersion, ":"); | ||
|
||
return firstSupportedVersion.isPresent() | ||
&& currentVersion.isPresent() | ||
&& currentVersion.get().left.compareTo(firstSupportedVersion.get().left) == 0 | ||
&& currentVersion.get().right.greaterThanOrEqualTo(firstSupportedVersion.get().right); | ||
} | ||
|
||
} |
This file contains 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 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
42 changes: 42 additions & 0 deletions
42
...ons-worker/src/test/java/io/airbyte/workers/helper/ConnectorDatadogSupportHelperTest.java
This file contains 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,42 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.helper; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import io.airbyte.commons.version.AirbyteVersion; | ||
import java.util.Optional; | ||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ConnectorDatadogSupportHelperTest { | ||
|
||
public static final String CONNECTOR_VERSION = "postgres=2.0.5"; | ||
private final ConnectorDatadogSupportHelper supportHelper = new ConnectorDatadogSupportHelper(); | ||
|
||
@Test | ||
void extractAirbyteVersionFromImageName() { | ||
final Optional<ImmutablePair<String, AirbyteVersion>> pair = | ||
supportHelper.extractAirbyteVersionFromImageName(CONNECTOR_VERSION, "="); | ||
|
||
assertTrue(pair.isPresent()); | ||
assertEquals("postgres".compareTo(pair.get().left), 0); | ||
assertEquals("2.0.5".compareTo(pair.get().right.serialize()), 0); | ||
} | ||
|
||
@Test | ||
void connectorVersionCompare() { | ||
assertTrue(supportHelper.connectorVersionCompare(CONNECTOR_VERSION, "postgres:2.0.5")); | ||
assertTrue(supportHelper.connectorVersionCompare(CONNECTOR_VERSION, "postgres:2.0.6")); | ||
|
||
assertFalse(supportHelper.connectorVersionCompare(CONNECTOR_VERSION, "postgres:2.0.4")); | ||
assertFalse(supportHelper.connectorVersionCompare(CONNECTOR_VERSION, "postgres:1.2.8")); | ||
|
||
assertFalse(supportHelper.connectorVersionCompare(CONNECTOR_VERSION, "mysql:2.0.5")); | ||
} | ||
|
||
} |
This file contains 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 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 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 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