-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Cloud Dashboard 1 #10628
Merged
Merged
Cloud Dashboard 1 #10628
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
36549cd
Checkpoint: Get create job metric working.
davinchia c4102ef
Add tags class.
davinchia ed433fa
Add tests.
davinchia 801ab3f
Add tests for jobIdToReleaseStages function and simplify SQL.
davinchia 80e1a00
Inject all metrics.
davinchia 8732204
Respond to PR feedback.
davinchia d636cc0
More method refactoring.
davinchia 83de723
Merge remote-tracking branch 'origin' into davinchia/cloud-dashboard-1
davinchia 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
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
47 changes: 47 additions & 0 deletions
47
airbyte-metrics/lib/src/main/java/io/airbyte/metrics/lib/MetricQueries.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,47 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.metrics.lib; | ||
|
||
import static io.airbyte.db.instance.configs.jooq.Tables.ACTOR; | ||
import static io.airbyte.db.instance.configs.jooq.Tables.ACTOR_DEFINITION; | ||
|
||
import io.airbyte.db.instance.configs.jooq.enums.ReleaseStage; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.jooq.DSLContext; | ||
|
||
/** | ||
* Keep track of all metric queries. | ||
*/ | ||
public class MetricQueries { | ||
|
||
public static List<ReleaseStage> jobIdToReleaseStages(final DSLContext ctx, final long jobId) { | ||
final var srcRelStageCol = "src_release_stage"; | ||
final var dstRelStageCol = "dst_release_stage"; | ||
|
||
final var query = String.format(""" | ||
select src_def_data.release_stage as %s, | ||
davinchia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dest_def_data.release_stage as %s | ||
from connection | ||
inner join jobs on connection.id=CAST(jobs.scope AS uuid) | ||
inner join actor as dest_data on connection.destination_id = dest_data.id | ||
inner join actor_definition as dest_def_data on dest_data.actor_definition_id = dest_def_data.id | ||
inner join actor as src_data on connection.source_id = src_data.id | ||
inner join actor_definition as src_def_data on src_data.actor_definition_id = src_def_data.id | ||
where jobs.id = '%d';""", srcRelStageCol, dstRelStageCol, jobId); | ||
|
||
final var res = ctx.fetch(query); | ||
final var stages = res.getValues(srcRelStageCol, ReleaseStage.class); | ||
stages.addAll(res.getValues(dstRelStageCol, ReleaseStage.class)); | ||
return stages; | ||
} | ||
|
||
public static List<ReleaseStage> srcIdAndDestIdToReleaseStages(final DSLContext ctx, final UUID srcId, final UUID dstId) { | ||
return ctx.select(ACTOR_DEFINITION.RELEASE_STAGE).from(ACTOR).join(ACTOR_DEFINITION).on(ACTOR.ACTOR_DEFINITION_ID.eq(ACTOR_DEFINITION.ID)) | ||
.where(ACTOR.ID.eq(srcId)) | ||
.or(ACTOR.ID.eq(dstId)).fetch().getValues(ACTOR_DEFINITION.RELEASE_STAGE); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
airbyte-metrics/lib/src/main/java/io/airbyte/metrics/lib/MetricTags.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,14 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.metrics.lib; | ||
|
||
/** | ||
* Keep track of all metric tags. | ||
*/ | ||
public class MetricTags { | ||
|
||
public static final String RELEASE_STAGE = "release_stage:"; | ||
|
||
} |
139 changes: 139 additions & 0 deletions
139
airbyte-metrics/lib/src/test/java/io/airbyte/metrics/llib/MetrisQueriesTest.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,139 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.metrics.llib; | ||
davinchia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import static io.airbyte.db.instance.configs.jooq.Tables.ACTOR; | ||
import static io.airbyte.db.instance.configs.jooq.Tables.ACTOR_DEFINITION; | ||
import static io.airbyte.db.instance.configs.jooq.Tables.CONNECTION; | ||
import static io.airbyte.db.instance.jobs.jooq.Tables.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.airbyte.db.Database; | ||
import io.airbyte.db.instance.configs.jooq.enums.ActorType; | ||
import io.airbyte.db.instance.configs.jooq.enums.NamespaceDefinitionType; | ||
import io.airbyte.db.instance.configs.jooq.enums.ReleaseStage; | ||
import io.airbyte.db.instance.test.TestDatabaseProviders; | ||
import io.airbyte.metrics.lib.MetricQueries; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.jooq.JSONB; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
public class MetrisQueriesTest { | ||
|
||
private static final String USER = "user"; | ||
private static final String PASS = "hunter2"; | ||
|
||
private static final UUID SRC_DEF_ID = UUID.randomUUID(); | ||
private static final UUID DST_DEF_ID = UUID.randomUUID(); | ||
|
||
private static PostgreSQLContainer<?> container; | ||
private static Database configDb; | ||
|
||
@BeforeAll | ||
static void setUpAll() throws IOException, SQLException { | ||
container = new PostgreSQLContainer<>("postgres:13-alpine") | ||
.withUsername(USER) | ||
.withPassword(PASS); | ||
container.start(); | ||
|
||
final TestDatabaseProviders databaseProviders = new TestDatabaseProviders(container); | ||
configDb = databaseProviders.createNewConfigsDatabase(); | ||
databaseProviders.createNewJobsDatabase(); | ||
|
||
// create src and dst def | ||
configDb.transaction(ctx -> ctx | ||
.insertInto(ACTOR_DEFINITION, ACTOR_DEFINITION.ID, ACTOR_DEFINITION.NAME, ACTOR_DEFINITION.DOCKER_REPOSITORY, | ||
ACTOR_DEFINITION.DOCKER_IMAGE_TAG, ACTOR_DEFINITION.SPEC, ACTOR_DEFINITION.ACTOR_TYPE, ACTOR_DEFINITION.RELEASE_STAGE) | ||
.values(SRC_DEF_ID, "srcDef", "repository", "tag", JSONB.valueOf("{}"), ActorType.source, ReleaseStage.beta) | ||
.values(DST_DEF_ID, "dstDef", "repository", "tag", JSONB.valueOf("{}"), ActorType.destination, ReleaseStage.generally_available) | ||
.values(UUID.randomUUID(), "dstDef", "repository", "tag", JSONB.valueOf("{}"), ActorType.destination, ReleaseStage.alpha).execute()); | ||
|
||
// drop the constraint to simplify following test set up | ||
configDb.transaction(ctx -> ctx.alterTable(ACTOR).dropForeignKey("actor_workspace_id_fkey").execute()); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() throws SQLException { | ||
configDb.transaction(ctx -> ctx.truncate(ACTOR)); | ||
} | ||
|
||
@Nested | ||
class srcIdAndDestIdToReleaseStages { | ||
|
||
@Test | ||
@DisplayName("should return the right release stages") | ||
void shouldReturnReleaseStages() throws SQLException { | ||
final var srcId = UUID.randomUUID(); | ||
final var dstId = UUID.randomUUID(); | ||
|
||
// create src and dst | ||
configDb.transaction( | ||
ctx -> ctx.insertInto(ACTOR, ACTOR.ID, ACTOR.WORKSPACE_ID, ACTOR.ACTOR_DEFINITION_ID, ACTOR.NAME, ACTOR.CONFIGURATION, ACTOR.ACTOR_TYPE) | ||
.values(srcId, UUID.randomUUID(), SRC_DEF_ID, "src", JSONB.valueOf("{}"), ActorType.source) | ||
.values(dstId, UUID.randomUUID(), DST_DEF_ID, "dst", JSONB.valueOf("{}"), ActorType.destination) | ||
.execute()); | ||
final var res = configDb.query(ctx -> MetricQueries.srcIdAndDestIdToReleaseStages(ctx, srcId, dstId)); | ||
assertEquals(List.of(ReleaseStage.beta, ReleaseStage.generally_available), res); | ||
} | ||
|
||
@Test | ||
@DisplayName("should not error out or return any result if not applicable") | ||
void shouldReturnNothingIfNotApplicable() throws SQLException { | ||
final var res = configDb.query(ctx -> MetricQueries.srcIdAndDestIdToReleaseStages(ctx, UUID.randomUUID(), UUID.randomUUID())); | ||
assertEquals(0, res.size()); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
class jobIdToReleaseStages { | ||
|
||
@Test | ||
@DisplayName("should return the right release stages") | ||
void shouldReturnReleaseStages() throws SQLException { | ||
final var srcId = UUID.randomUUID(); | ||
final var dstId = UUID.randomUUID(); | ||
// create src and dst | ||
configDb.transaction( | ||
ctx -> ctx.insertInto(ACTOR, ACTOR.ID, ACTOR.WORKSPACE_ID, ACTOR.ACTOR_DEFINITION_ID, ACTOR.NAME, ACTOR.CONFIGURATION, ACTOR.ACTOR_TYPE) | ||
.values(srcId, UUID.randomUUID(), SRC_DEF_ID, "src", JSONB.valueOf("{}"), ActorType.source) | ||
.values(dstId, UUID.randomUUID(), DST_DEF_ID, "dst", JSONB.valueOf("{}"), ActorType.destination) | ||
.execute()); | ||
final var connId = UUID.randomUUID(); | ||
// create connection | ||
configDb.transaction( | ||
ctx -> ctx | ||
.insertInto(CONNECTION, CONNECTION.ID, CONNECTION.NAMESPACE_DEFINITION, CONNECTION.SOURCE_ID, CONNECTION.DESTINATION_ID, | ||
CONNECTION.NAME, CONNECTION.CATALOG, CONNECTION.MANUAL) | ||
.values(connId, NamespaceDefinitionType.source, srcId, dstId, "conn", JSONB.valueOf("{}"), true) | ||
.execute()); | ||
// create job | ||
final var jobId = 1L; | ||
configDb.transaction( | ||
ctx -> ctx.insertInto(JOBS, JOBS.ID, JOBS.SCOPE).values(jobId, connId.toString()).execute()); | ||
|
||
final var res = configDb.query(ctx -> MetricQueries.jobIdToReleaseStages(ctx, jobId)); | ||
assertEquals(List.of(ReleaseStage.beta, ReleaseStage.generally_available), res); | ||
} | ||
|
||
@Test | ||
@DisplayName("should not error out or return any result if not applicable") | ||
void shouldReturnNothingIfNotApplicable() throws SQLException { | ||
final var missingJobId = 100000L; | ||
final var res = configDb.query(ctx -> MetricQueries.jobIdToReleaseStages(ctx, missingJobId)); | ||
assertEquals(0, res.size()); | ||
} | ||
|
||
} | ||
|
||
} |
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.
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.
required to run a query against the database.
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.
@davinchia this is breaking the whole point of the
ConfigRepository
abstraction. It also sets an example for everyone else who joins the team that the db can now be accessed from anywhere in code which is a pattern we have worked really hard to avoid.Is there a reason you can't write your query inside here instead like we do with other queries?
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.
My mental context at time of writing:
I'm happy to move the queries here if you have feel otherwise.