Skip to content
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

Track number of streams in syncs #15478

Merged
merged 3 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,12 @@ private Map<String, Object> generateSyncMetadata(final UUID connectionId) throws
operationUsage.put(OPERATION + operation.getOperatorType(), usageCount + 1);
}
}
return MoreMaps.merge(TrackingMetadata.generateSyncMetadata(standardSync), operationUsage);

final Map<String, Object> streamCountData = new HashMap<>();
final Integer streamCount = standardSync.getCatalog().getStreams().size();
streamCountData.put("number_of_streams", streamCount);

return MoreMaps.merge(TrackingMetadata.generateSyncMetadata(standardSync), operationUsage, streamCountData);
}

private static ImmutableMap<String, Object> generateStateMetadata(final JobState jobState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
import io.airbyte.config.StandardWorkspace;
import io.airbyte.config.persistence.ConfigNotFoundException;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.protocol.models.CatalogHelpers;
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog;
import io.airbyte.protocol.models.ConfiguredAirbyteStream;
import io.airbyte.protocol.models.ConnectorSpecification;
import io.airbyte.protocol.models.DestinationSyncMode;
import io.airbyte.protocol.models.Field;
import io.airbyte.protocol.models.JsonSchemaType;
import io.airbyte.protocol.models.SyncMode;
import io.airbyte.scheduler.models.Attempt;
import io.airbyte.scheduler.models.Job;
Expand Down Expand Up @@ -112,6 +115,9 @@ class JobTrackerTest {
.put("table_prefix", false)
.put("operation_count", 0)
.build();
private static final ConfiguredAirbyteCatalog CATALOG = CatalogHelpers
.createConfiguredAirbyteCatalog("stream_name", "stream_namespace",
Field.of("int_field", JsonSchemaType.NUMBER));

private static final ConnectorSpecification SOURCE_SPEC;
private static final ConnectorSpecification DESTINATION_SPEC;
Expand Down Expand Up @@ -269,7 +275,9 @@ void testAsynchronous(final ConfigType configType, final Map<String, Object> add
final ImmutableMap<String, Object> metadata = getJobMetadata(configType, jobId);
final Job job = getJobMock(configType, jobId);
// test when frequency is manual.
when(configRepository.getStandardSync(CONNECTION_ID)).thenReturn(new StandardSync().withConnectionId(CONNECTION_ID).withManual(true));

when(configRepository.getStandardSync(CONNECTION_ID))
.thenReturn(new StandardSync().withConnectionId(CONNECTION_ID).withManual(true).withCatalog(CATALOG));
when(configRepository.getStandardWorkspace(WORKSPACE_ID, true))
.thenReturn(new StandardWorkspace().withWorkspaceId(WORKSPACE_ID).withName(WORKSPACE_NAME));
final Map<String, Object> manualMetadata = MoreMaps.merge(
Expand All @@ -280,7 +288,7 @@ void testAsynchronous(final ConfigType configType, final Map<String, Object> add

// test when frequency is scheduled.
when(configRepository.getStandardSync(CONNECTION_ID))
.thenReturn(new StandardSync().withConnectionId(CONNECTION_ID).withManual(false)
.thenReturn(new StandardSync().withConnectionId(CONNECTION_ID).withManual(false).withCatalog(CATALOG)
.withSchedule(new Schedule().withUnits(1L).withTimeUnit(TimeUnit.MINUTES)));
final Map<String, Object> scheduledMetadata = MoreMaps.merge(
metadata,
Expand Down Expand Up @@ -387,7 +395,8 @@ void testAsynchronousAttempt(final ConfigType configType, final Job job, final M

final ImmutableMap<String, Object> metadata = getJobMetadata(configType, LONG_JOB_ID);
// test when frequency is manual.
when(configRepository.getStandardSync(CONNECTION_ID)).thenReturn(new StandardSync().withConnectionId(CONNECTION_ID).withManual(true));
when(configRepository.getStandardSync(CONNECTION_ID))
.thenReturn(new StandardSync().withConnectionId(CONNECTION_ID).withManual(true).withCatalog(CATALOG));
when(workspaceHelper.getWorkspaceForJobIdIgnoreExceptions(LONG_JOB_ID)).thenReturn(WORKSPACE_ID);
when(configRepository.getStandardWorkspace(WORKSPACE_ID, true))
.thenReturn(new StandardWorkspace().withWorkspaceId(WORKSPACE_ID).withName(WORKSPACE_NAME));
Expand Down Expand Up @@ -556,6 +565,7 @@ private ImmutableMap<String, Object> getJobMetadata(final ConfigType configType,
.put("namespace_definition", NamespaceDefinitionType.SOURCE)
.put("table_prefix", false)
.put("operation_count", 0)
.put("number_of_streams", 1)
.build();
}

Expand Down