-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid uncatched exception (#13137)
- Loading branch information
1 parent
763603f
commit 993395c
Showing
11 changed files
with
276 additions
and
155 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
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
32 changes: 32 additions & 0 deletions
32
...main/java/io/airbyte/workers/temporal/discover/catalog/DiscoverCatalogHelperActivity.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,32 @@ | ||
/* | ||
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.temporal.discover.catalog; | ||
|
||
import io.airbyte.workers.models.PostprocessCatalogInput; | ||
import io.airbyte.workers.models.PostprocessCatalogOutput; | ||
import io.temporal.activity.ActivityInterface; | ||
import io.temporal.activity.ActivityMethod; | ||
import java.util.UUID; | ||
|
||
@ActivityInterface | ||
public interface DiscoverCatalogHelperActivity { | ||
|
||
@ActivityMethod | ||
boolean shouldUseWorkload(final UUID workspaceId); | ||
|
||
@ActivityMethod | ||
void reportSuccess(final Boolean workloadEnabled); | ||
|
||
@ActivityMethod | ||
void reportFailure(final Boolean workloadEnabled); | ||
|
||
/** | ||
* Perform catalog diffing, subsequent disabling of the connection and any other necessary | ||
* operations after performing the discover. | ||
*/ | ||
@ActivityMethod | ||
PostprocessCatalogOutput postprocess(final PostprocessCatalogInput input); | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
.../java/io/airbyte/workers/temporal/discover/catalog/DiscoverCatalogHelperActivityImpl.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,85 @@ | ||
/* | ||
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.temporal.discover.catalog; | ||
|
||
import io.airbyte.api.client.AirbyteApiClient; | ||
import io.airbyte.api.client.model.generated.PostprocessDiscoveredCatalogRequestBody; | ||
import io.airbyte.api.client.model.generated.PostprocessDiscoveredCatalogResult; | ||
import io.airbyte.featureflag.Empty; | ||
import io.airbyte.featureflag.FeatureFlagClient; | ||
import io.airbyte.featureflag.UseWorkloadApi; | ||
import io.airbyte.featureflag.WorkloadApiServerEnabled; | ||
import io.airbyte.featureflag.WorkloadLauncherEnabled; | ||
import io.airbyte.featureflag.Workspace; | ||
import io.airbyte.metrics.lib.MetricAttribute; | ||
import io.airbyte.metrics.lib.MetricClient; | ||
import io.airbyte.metrics.lib.MetricTags; | ||
import io.airbyte.metrics.lib.OssMetricsRegistry; | ||
import io.airbyte.workers.helper.CatalogDiffConverter; | ||
import io.airbyte.workers.models.PostprocessCatalogInput; | ||
import io.airbyte.workers.models.PostprocessCatalogOutput; | ||
import jakarta.inject.Singleton; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
@Singleton | ||
public class DiscoverCatalogHelperActivityImpl implements DiscoverCatalogHelperActivity { | ||
|
||
private final AirbyteApiClient airbyteApiClient; | ||
private final FeatureFlagClient featureFlagClient; | ||
private final MetricClient metricClient; | ||
|
||
public DiscoverCatalogHelperActivityImpl(AirbyteApiClient airbyteApiClient, FeatureFlagClient featureFlagClient, MetricClient metricClient) { | ||
this.airbyteApiClient = airbyteApiClient; | ||
this.featureFlagClient = featureFlagClient; | ||
this.metricClient = metricClient; | ||
} | ||
|
||
@Override | ||
public boolean shouldUseWorkload(final UUID workspaceId) { | ||
var ffCheck = featureFlagClient.boolVariation(UseWorkloadApi.INSTANCE, new Workspace(workspaceId)); | ||
var envCheck = featureFlagClient.boolVariation(WorkloadLauncherEnabled.INSTANCE, Empty.INSTANCE) | ||
&& featureFlagClient.boolVariation(WorkloadApiServerEnabled.INSTANCE, Empty.INSTANCE); | ||
|
||
return ffCheck || envCheck; | ||
} | ||
|
||
@Override | ||
public void reportSuccess(final Boolean workloadEnabled) { | ||
final var workloadEnabledStr = workloadEnabled != null ? workloadEnabled.toString() : "unknown"; | ||
metricClient.count(OssMetricsRegistry.CATALOG_DISCOVERY, 1, | ||
new MetricAttribute(MetricTags.STATUS, "success"), | ||
new MetricAttribute("workload_enabled", workloadEnabledStr)); | ||
} | ||
|
||
@Override | ||
public void reportFailure(final Boolean workloadEnabled) { | ||
final var workloadEnabledStr = workloadEnabled != null ? workloadEnabled.toString() : "unknown"; | ||
metricClient.count(OssMetricsRegistry.CATALOG_DISCOVERY, 1, | ||
new MetricAttribute(MetricTags.STATUS, "failed"), | ||
new MetricAttribute("workload_enabled", workloadEnabledStr)); | ||
} | ||
|
||
@Override | ||
public PostprocessCatalogOutput postprocess(final PostprocessCatalogInput input) { | ||
try { | ||
Objects.requireNonNull(input.getConnectionId()); | ||
Objects.requireNonNull(input.getCatalogId()); | ||
|
||
final var reqBody = new PostprocessDiscoveredCatalogRequestBody( | ||
input.getCatalogId(), | ||
input.getConnectionId()); | ||
|
||
final PostprocessDiscoveredCatalogResult resp = airbyteApiClient.getConnectionApi().postprocessDiscoveredCatalogForConnection(reqBody); | ||
|
||
final var domainDiff = resp.getAppliedDiff() != null ? CatalogDiffConverter.toDomain(resp.getAppliedDiff()) : null; | ||
|
||
return PostprocessCatalogOutput.Companion.success(domainDiff); | ||
} catch (final Exception e) { | ||
return PostprocessCatalogOutput.Companion.failure(e); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.