-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Populate and read from SyncStats table #16476
Merged
Merged
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
31e12b1
Sync stats migration
alovew 79662b6
migration
alovew ee4c964
Revert "Sync stats migration"
alovew 2524f50
schema
alovew 3b1e7f8
remove todo comment
alovew c760f08
primary key and foreign key constraints
alovew c8a60d0
remove foreign key reference
alovew 63ea03e
format
alovew 701d636
move sync stats migration to jobs db
alovew 8fe7c4d
format
alovew 5ea3325
cascade truncate
alovew 58a71c3
populate sync stats
alovew 4f6c994
write to sync stats
alovew c3e886e
write and read sync stats
alovew 0d1275c
simplify read
alovew 98ab3f9
fix records emitted/committed
alovew a56ec6e
update
alovew 1103c12
Merge branch 'master' into anne/populate-sync-stats
alovew 9fa76fb
Merge branch 'master' into anne/populate-sync-stats
alovew 94c6de0
Merge branch 'master' into anne/populate-sync-stats
alovew 0fd53d1
Merge branch 'master' into anne/populate-sync-stats
alovew 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 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
34 changes: 34 additions & 0 deletions
34
...n/java/io/airbyte/db/instance/jobs/migrations/V0_40_4_001__ChangeSyncStatsForeignKey.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,34 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.db.instance.jobs.migrations; | ||
|
||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.jooq.DSLContext; | ||
import org.jooq.impl.DSL; | ||
import org.jooq.impl.SQLDataType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class V0_40_4_001__ChangeSyncStatsForeignKey extends BaseJavaMigration { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(V0_40_4_001__ChangeSyncStatsForeignKey.class); | ||
|
||
@Override | ||
public void migrate(final Context context) throws Exception { | ||
LOGGER.info("Running migration: {}", this.getClass().getSimpleName()); | ||
|
||
// Warning: please do not use any jOOQ generated code to write a migration. | ||
// As database schema changes, the generated jOOQ code can be deprecated. So | ||
// old migration may not compile if there is any generated code. | ||
final DSLContext ctx = DSL.using(context.getConnection()); | ||
changeForeignKeyType(ctx); | ||
} | ||
|
||
private void changeForeignKeyType(final DSLContext ctx) throws Exception { | ||
ctx.alterTable("sync_stats").alter("attempt_id").set(SQLDataType.BIGINT.nullable(false)).execute(); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,9 @@ | |
import io.airbyte.config.JobGetSpecConfig; | ||
import io.airbyte.config.JobOutput; | ||
import io.airbyte.config.JobSyncConfig; | ||
import io.airbyte.config.StandardSyncOutput; | ||
import io.airbyte.config.StandardSyncSummary; | ||
import io.airbyte.config.SyncStats; | ||
import io.airbyte.db.Database; | ||
import io.airbyte.db.factory.DSLContextFactory; | ||
import io.airbyte.db.factory.DataSourceFactory; | ||
|
@@ -249,14 +252,34 @@ void testWriteOutput() throws IOException { | |
final long jobId = jobPersistence.enqueueJob(SCOPE, SPEC_JOB_CONFIG).orElseThrow(); | ||
final int attemptNumber = jobPersistence.createAttempt(jobId, LOG_PATH); | ||
final Job created = jobPersistence.getJob(jobId); | ||
final JobOutput jobOutput = new JobOutput().withOutputType(JobOutput.OutputType.DISCOVER_CATALOG); | ||
final SyncStats syncStats = | ||
new SyncStats().withBytesEmitted(100L).withRecordsEmitted(10L).withRecordsCommitted(10L).withDestinationStateMessagesEmitted(1L) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Different values for |
||
.withSourceStateMessagesEmitted(4L).withMaxSecondsBeforeSourceStateMessageEmitted(5L).withMeanSecondsBeforeSourceStateMessageEmitted(2L) | ||
.withMaxSecondsBetweenStateMessageEmittedandCommitted(10L).withMeanSecondsBetweenStateMessageEmittedandCommitted(3L); | ||
final StandardSyncOutput standardSyncOutput = | ||
new StandardSyncOutput().withStandardSyncSummary(new StandardSyncSummary().withTotalStats(syncStats)); | ||
final JobOutput jobOutput = new JobOutput().withOutputType(JobOutput.OutputType.DISCOVER_CATALOG).withSync(standardSyncOutput); | ||
|
||
when(timeSupplier.get()).thenReturn(Instant.ofEpochMilli(4242)); | ||
jobPersistence.writeOutput(jobId, attemptNumber, jobOutput); | ||
jobPersistence.writeOutput(jobId, attemptNumber, jobOutput, | ||
jobOutput.getSync().getStandardSyncSummary().getTotalStats()); | ||
|
||
final Job updated = jobPersistence.getJob(jobId); | ||
assertEquals(Optional.of(jobOutput), updated.getAttempts().get(0).getOutput()); | ||
assertNotEquals(created.getAttempts().get(0).getUpdatedAtInSecond(), updated.getAttempts().get(0).getUpdatedAtInSecond()); | ||
assertNotEquals(created.getAttempts().get(0).getUpdatedAtInSecond(), | ||
updated.getAttempts().get(0).getUpdatedAtInSecond()); | ||
|
||
final SyncStats storedSyncStats = jobPersistence.getSyncStats(updated.getId()).stream().findFirst().get(); | ||
assertEquals(100L, storedSyncStats.getBytesEmitted()); | ||
assertEquals(10L, storedSyncStats.getRecordsEmitted()); | ||
assertEquals(10L, storedSyncStats.getRecordsCommitted()); | ||
assertEquals(4L, storedSyncStats.getSourceStateMessagesEmitted()); | ||
assertEquals(1L, storedSyncStats.getDestinationStateMessagesEmitted()); | ||
assertEquals(5L, storedSyncStats.getMaxSecondsBeforeSourceStateMessageEmitted()); | ||
assertEquals(2L, storedSyncStats.getMeanSecondsBeforeSourceStateMessageEmitted()); | ||
assertEquals(10L, storedSyncStats.getMaxSecondsBetweenStateMessageEmittedandCommitted()); | ||
assertEquals(3L, storedSyncStats.getMeanSecondsBetweenStateMessageEmittedandCommitted()); | ||
|
||
} | ||
|
||
@Test | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getRecordsCommitted
?