Skip to content

Commit

Permalink
Expose version as AirbyteVersion instead of String in Configs iface (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cgardens committed Oct 26, 2021
1 parent 85851b7 commit 6ff2fc7
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void track(final UUID workspaceId, final String action) {
@Override
public void track(final UUID workspaceId, final String action, final Map<String, Object> metadata) {
LOGGER.info("track. version: {}, userId: {}, action: {}, metadata: {}",
identityFetcher.apply(workspaceId).getAirbyteVersion(),
identityFetcher.apply(workspaceId).getAirbyteVersion().serialize(),
identityFetcher.apply(workspaceId).getCustomerId(),
action,
metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void identify(final UUID workspaceId) {
final Map<String, Object> identityMetadata = new HashMap<>();

// deployment
identityMetadata.put(AIRBYTE_VERSION_KEY, trackingIdentity.getAirbyteVersion());
identityMetadata.put(AIRBYTE_VERSION_KEY, trackingIdentity.getAirbyteVersion().serialize());
identityMetadata.put("deployment_mode", deployment.getDeploymentMode());
identityMetadata.put("deployment_env", deployment.getDeploymentEnv());
identityMetadata.put("deployment_id", deployment.getDeploymentId());
Expand Down Expand Up @@ -88,7 +88,7 @@ public void track(final UUID workspaceId, final String action) {
public void track(final UUID workspaceId, final String action, final Map<String, Object> metadata) {
final Map<String, Object> mapCopy = new HashMap<>(metadata);
final TrackingIdentity trackingIdentity = identityFetcher.apply(workspaceId);
mapCopy.put(AIRBYTE_VERSION_KEY, trackingIdentity.getAirbyteVersion());
mapCopy.put(AIRBYTE_VERSION_KEY, trackingIdentity.getAirbyteVersion().serialize());
if (!metadata.isEmpty()) {
trackingIdentity.getEmail().ifPresent(email -> mapCopy.put("email", email));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.airbyte.analytics;

import com.google.common.annotations.VisibleForTesting;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.Configs;
import io.airbyte.config.StandardWorkspace;
import io.airbyte.config.persistence.ConfigNotFoundException;
Expand Down Expand Up @@ -38,7 +39,7 @@ static void initialize(final TrackingClient trackingClient) {
public static void initialize(final Configs.TrackingStrategy trackingStrategy,
final Deployment deployment,
final String airbyteRole,
final String airbyteVersion,
final AirbyteVersion airbyteVersion,
final ConfigRepository configRepository) {
initialize(createTrackingClient(
trackingStrategy,
Expand All @@ -53,7 +54,7 @@ private static void initialize() {
}

@VisibleForTesting
static TrackingIdentity getTrackingIdentity(final ConfigRepository configRepository, final String airbyteVersion, final UUID workspaceId) {
static TrackingIdentity getTrackingIdentity(final ConfigRepository configRepository, final AirbyteVersion airbyteVersion, final UUID workspaceId) {
try {
final StandardWorkspace workspace = configRepository.getStandardWorkspace(workspaceId, true);
String email = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

package io.airbyte.analytics;

import io.airbyte.commons.version.AirbyteVersion;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

public class TrackingIdentity {

private final String airbyteVersion;
private final AirbyteVersion airbyteVersion;
private final UUID customerId;
private final String email;
private final Boolean anonymousDataCollection;
Expand All @@ -22,7 +23,7 @@ public static TrackingIdentity empty() {
}

public TrackingIdentity(
final String airbyteVersion,
final AirbyteVersion airbyteVersion,
final UUID customerId,
final String email,
final Boolean anonymousDataCollection,
Expand All @@ -36,7 +37,7 @@ public TrackingIdentity(
this.securityUpdates = securityUpdates;
}

public String getAirbyteVersion() {
public AirbyteVersion getAirbyteVersion() {
return airbyteVersion;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.segment.analytics.Analytics;
import com.segment.analytics.messages.IdentifyMessage;
import com.segment.analytics.messages.TrackMessage;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.Configs;
import io.airbyte.config.Configs.WorkerEnvironment;
import java.util.Map;
Expand All @@ -25,7 +26,7 @@

class SegmentTrackingClientTest {

private static final String AIRBYTE_VERSION = "dev";
private static final AirbyteVersion AIRBYTE_VERSION = new AirbyteVersion("dev");
private static final Deployment DEPLOYMENT = new Deployment(Configs.DeploymentMode.OSS, UUID.randomUUID(), WorkerEnvironment.DOCKER);
private static final String EMAIL = "a@airbyte.io";
private static final TrackingIdentity IDENTITY = new TrackingIdentity(AIRBYTE_VERSION, UUID.randomUUID(), EMAIL, false, false, true);
Expand Down Expand Up @@ -59,7 +60,7 @@ void testIdentify() {
.put("deployment_env", DEPLOYMENT.getDeploymentEnv())
.put("deployment_mode", DEPLOYMENT.getDeploymentMode())
.put("deployment_id", DEPLOYMENT.getDeploymentId())
.put("airbyte_version", AIRBYTE_VERSION)
.put("airbyte_version", AIRBYTE_VERSION.serialize())
.put("email", IDENTITY.getEmail().get())
.put("anonymized", IDENTITY.isAnonymousDataCollection())
.put("subscribed_newsletter", IDENTITY.isNews())
Expand All @@ -85,7 +86,7 @@ void testIdentifyWithRole() {
.put("deployment_env", DEPLOYMENT.getDeploymentEnv())
.put("deployment_mode", DEPLOYMENT.getDeploymentMode())
.put("deployment_id", DEPLOYMENT.getDeploymentId())
.put("airbyte_version", AIRBYTE_VERSION)
.put("airbyte_version", AIRBYTE_VERSION.serialize())
.put("email", IDENTITY.getEmail().get())
.put("anonymized", IDENTITY.isAnonymousDataCollection())
.put("subscribed_newsletter", IDENTITY.isNews())
Expand All @@ -99,7 +100,7 @@ void testIdentifyWithRole() {
@Test
void testTrack() {
final ArgumentCaptor<TrackMessage.Builder> mockBuilder = ArgumentCaptor.forClass(TrackMessage.Builder.class);
final ImmutableMap<String, Object> metadata = ImmutableMap.of("airbyte_version", AIRBYTE_VERSION);
final ImmutableMap<String, Object> metadata = ImmutableMap.of("airbyte_version", AIRBYTE_VERSION.serialize());

segmentTrackingClient.track(WORKSPACE_ID, "jump");

Expand All @@ -116,7 +117,7 @@ void testTrackWithMetadata() {
final ImmutableMap<String, Object> metadata = ImmutableMap.of(
"height", "80 meters",
"email", EMAIL,
"airbyte_version", AIRBYTE_VERSION);
"airbyte_version", AIRBYTE_VERSION.serialize());

segmentTrackingClient.track(WORKSPACE_ID, "jump", metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.Configs;
import io.airbyte.config.Configs.WorkerEnvironment;
import io.airbyte.config.StandardWorkspace;
Expand All @@ -24,7 +25,7 @@
class TrackingClientSingletonTest {

private static final UUID WORKSPACE_ID = UUID.randomUUID();
private static final String AIRBYTE_VERSION = "dev";
private static final AirbyteVersion AIRBYTE_VERSION = new AirbyteVersion("dev");
private static final String EMAIL = "a@airbyte.io";
private static final Deployment DEPLOYMENT = new Deployment(Configs.DeploymentMode.OSS, UUID.randomUUID(), WorkerEnvironment.DOCKER);
private static final TrackingIdentity IDENTITY = new TrackingIdentity(AIRBYTE_VERSION, UUID.randomUUID(), EMAIL, false, false, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.airbyte.commons.version;

import com.google.common.base.Preconditions;
import java.util.Objects;

/**
* The AirbyteVersion identifies the version of the database used internally by Airbyte services.
Expand Down Expand Up @@ -166,4 +167,22 @@ public static AirbyteVersion versionWithoutPatch(final String airbyteVersion) {
return versionWithoutPatch(new AirbyteVersion(airbyteVersion));
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final AirbyteVersion that = (AirbyteVersion) o;
return Objects.equals(version, that.version) && Objects.equals(major, that.major) && Objects.equals(minor, that.minor)
&& Objects.equals(patch, that.patch);
}

@Override
public int hashCode() {
return Objects.hash(version, major, minor, patch);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.airbyte.config;

import io.airbyte.commons.version.AirbyteVersion;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
Expand All @@ -13,7 +14,7 @@ public interface Configs {

String getAirbyteRole();

String getAirbyteVersion();
AirbyteVersion getAirbyteVersion();

String getAirbyteApiHost();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.helpers.LogClientSingleton;
import java.nio.file.Path;
import java.util.Arrays;
Expand Down Expand Up @@ -117,8 +118,8 @@ public int getAirbyteApiPort() {
}

@Override
public String getAirbyteVersion() {
return getEnsureEnv(AIRBYTE_VERSION);
public AirbyteVersion getAirbyteVersion() {
return new AirbyteVersion(getEnsureEnv(AIRBYTE_VERSION));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import static org.mockito.Mockito.when;

import io.airbyte.commons.version.AirbyteVersion;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -47,7 +48,7 @@ void testAirbyteVersion() {
Assertions.assertThrows(IllegalArgumentException.class, () -> config.getAirbyteVersion());

when(function.apply(EnvConfigs.AIRBYTE_VERSION)).thenReturn("dev");
Assertions.assertEquals("dev", config.getAirbyteVersion());
Assertions.assertEquals(new AirbyteVersion("dev"), config.getAirbyteVersion());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static void main(final String[] args) throws IOException, InterruptedExce
workspaceRoot,
jobPersistence);
AirbyteVersion.assertIsCompatible(
new AirbyteVersion(configs.getAirbyteVersion()),
configs.getAirbyteVersion(),
jobPersistence.getVersion().map(AirbyteVersion::new).orElseThrow());

TrackingClientSingleton.initialize(
Expand Down
8 changes: 4 additions & 4 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public class ServerApp implements ServerRunnable {
* wouldn't run
*/
private static final AirbyteVersion KUBE_SUPPORT_FOR_AUTOMATIC_MIGRATION = new AirbyteVersion("0.26.5-alpha");
private final String airbyteVersion;
private final AirbyteVersion airbyteVersion;
private final Set<Class<?>> customComponentClasses;
private final Set<Object> customComponents;

public ServerApp(final String airbyteVersion,
public ServerApp(final AirbyteVersion airbyteVersion,
final Set<Class<?>> customComponentClasses,
final Set<Object> customComponents) {
this.airbyteVersion = airbyteVersion;
Expand Down Expand Up @@ -120,7 +120,7 @@ public void start() throws Exception {

server.start();
final String banner = MoreResources.readResource("banner/banner.txt");
LOGGER.info(banner + String.format("Version: %s\n", airbyteVersion));
LOGGER.info(banner + String.format("Version: %s\n", airbyteVersion.serialize()));
server.join();
}

Expand Down Expand Up @@ -199,7 +199,7 @@ public static ServerRunnable getServer(final ServerFactory apiFactory, final Con
// if no workspace exists, we create one so the user starts out with a place to add configuration.
createWorkspaceIfNoneExists(configRepository);

final AirbyteVersion airbyteVersion = new AirbyteVersion(configs.getAirbyteVersion());
final AirbyteVersion airbyteVersion = configs.getAirbyteVersion();
if (jobPersistence.getVersion().isEmpty()) {
LOGGER.info(String.format("Setting Database version to %s...", airbyteVersion));
jobPersistence.setVersion(airbyteVersion.serialize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import io.airbyte.api.model.WorkspaceReadList;
import io.airbyte.api.model.WorkspaceUpdate;
import io.airbyte.commons.io.FileTtlManager;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.Configs;
import io.airbyte.config.persistence.ConfigNotFoundException;
import io.airbyte.config.persistence.ConfigPersistence;
Expand Down Expand Up @@ -193,7 +192,7 @@ public ConfigurationApi(final ConfigRepository configRepository,
webBackendDestinationsHandler = new WebBackendDestinationsHandler(destinationHandler, configRepository, trackingClient);
healthCheckHandler = new HealthCheckHandler(configRepository);
archiveHandler = new ArchiveHandler(
new AirbyteVersion(configs.getAirbyteVersion()),
configs.getAirbyteVersion(),
configRepository,
jobPersistence,
seed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import io.airbyte.analytics.TrackingClient;
import io.airbyte.commons.io.FileTtlManager;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.Configs;
import io.airbyte.config.persistence.ConfigPersistence;
import io.airbyte.config.persistence.ConfigRepository;
Expand All @@ -25,7 +26,7 @@ public class ConfigurationApiTest {
@Test
void testImportDefinitions() {
final Configs configs = mock(Configs.class);
when(configs.getAirbyteVersion()).thenReturn("0.1.0-alpha");
when(configs.getAirbyteVersion()).thenReturn(new AirbyteVersion("0.1.0-alpha"));
when(configs.getWebappUrl()).thenReturn("http://localhost");

final ConfigurationApi configurationApi = new ConfigurationApi(
Expand Down

0 comments on commit 6ff2fc7

Please sign in to comment.