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

convert airbyte-metrics-reporter to micronaut #17365

Merged
merged 29 commits into from
Oct 11, 2022

Conversation

colesnodgrass
Copy link
Member

@colesnodgrass colesnodgrass commented Sep 28, 2022

What

  • Update airbyte-metrics-reporter to be Micronaut based.

How

  • Update staticReporterApp.configDatabase and MietricClientFactory.getMetricClient() calls with constructor injected beans MetricRepository and MetricClient dependencies which are defined in the ReporterFactory class.
  • Move all queries specific to the metric-reporter from metrics-lib/MetricQueries to the MetricRepository class in the reporter module.
    • Additionally the visibility of these methods was changed from public to package-private as there is no reason for these to be available outside of this use-case.
  • Move the metric emitter initialization from the main function to a Micronaut annotated @EventListener in the EventListeners class.
    • This was previously handled by the ReporterApp.
    • This handles both starting and cleaning stopping the emitters by listening for ApplicationStartupEvent and ApplicationShutdownEvent events.
  • Remove all flyway references.
    • They seemed out of place in a service like this.
  • Replace ToEmit enum with a sealed Emitter class.
    • Each implementation of the Emitter class is responsible for a single metric.
    • Each implementation of the Emitter class has its dependencies injected via it's constructor.
    • Each implementation of the Emitter class is annotated with @Singleton and supports being injected.
  • Add tests for the classes that implement the Emitter class.

Recommended reading order

  1. Application.java
  2. ReporterFactory.java
  3. EventListeners.java
  4. MetricRepository.java
    1. Everything was copied from MetricQueries.java and slightly cleaned up, including the tests.
  5. Emitter.java
  6. build.gradle
  7. application.yml

Note

I will be updating some of the queries used to gather these metrics in a follow-up PR as they are inefficient. This was not done as part of this PR as it's worth reviewing those changes independent of the Micronaut changes.

jackson-converter-enabled: true
sql-dialect: POSTGRES

docker:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed for this application?

access:
- isAnonymous()
server:
port: 9000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9000 is the port that airbyte-workers used before the conversion. I'm not sure if this will be an issue when running via Docker Compose, as that port is already mapped to something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdpgrailsdev looks like we're using the same port in a few places:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was originally added to airbyte-workers, as it was already using port 9000. I believe it is copy/pasta in airbyte-cron. This is probably fine because the containers/pods will handle mapping to it and we can cycle back later if we want to have the services on different ports for identification, etc.

@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 29, 2022 16:26 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 29, 2022 18:05 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 29, 2022 20:10 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 29, 2022 23:43 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 30, 2022 03:25 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 30, 2022 16:36 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 30, 2022 17:25 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 30, 2022 18:59 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 30, 2022 19:15 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 30, 2022 22:03 Inactive
@colesnodgrass colesnodgrass temporarily deployed to more-secrets September 30, 2022 23:15 Inactive
testAnnotationProcessor libs.bundles.micronaut.test.annotation.processor

// integrationTestJavaAnnotationProcessor platform(libs.micronaut.bom)
// integrationTestJavaAnnotationProcessor libs.bundles.micronaut.test.annotation.processor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove the commented out dependencies if not needed

Copy link
Contributor

@jdpgrailsdev jdpgrailsdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: with a few minor nits/comments.

@jdpgrailsdev
Copy link
Contributor

@colesnodgrass Bonus points if you want to also include a startup banner: https://github.com/airbytehq/airbyte/blob/master/airbyte-workers/src/main/resources/micronaut-banner.txt

@colesnodgrass colesnodgrass temporarily deployed to more-secrets October 10, 2022 20:07 Inactive
* @return Duration of how often this metric should report.
*/
public Duration getDuration() {
return Duration.ofSeconds(15);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you we need that? Isn't the Datadog agent supposed to do that for us? Won't this be an issue if we have metrics that are different than a gauge?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As these are stats which are emitted to the datadog statsd agent, there is no way (that I'm currently aware of) to tell this agent to fetch these values on a period basis. They are not polled by the agent, but rather are pushed to the agent. This is why these are registered to run in the EventListeners class at a fixed rate. The rate of which is determined by what duration is returned from this getDuration method.

Not every value is currently running every 15 seconds, some run every hour.

As for the non-gauge values, all of these emitters should match the existing behavior from the now defunct ToEmit enum. If they were working before they should still be working.

@@ -1 +1,8 @@
: airbyte-metrics-reporter :

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinon here but seeing the Airbyte banner, was the sign for me that my local deployment can be use. Having many of them will be confusing. If we decide on keeping them we should add it to the cron app as well.

}

List<Long> numberOfActiveConnPerWorkspace() {
final var query = """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to use not use JOOQ here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied verbatim from the existing implementation. I didn't want to move and change them within the same PR as I find that makes it's difficult to actually track the query changes. I plan to do a follow-up PR that cleans these queries up a bit.

return ctx.fetch(query).getValues("num_conn", long.class);
}

long numScheduledActiveConnectionsInLastDay() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we going to miss some connection here? expecially the cron and the manual ones that have been triggered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly? This was also copied verbatim from the existing implementation. See my comments above about a follow-up PR.

and j.created_at > now() - interval '24 hours 1 minutes'
and c.status = 'active'
and j.config_type = 'sync'
and c.updated_at < now() - interval '24 hours 1 minutes'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the filter on the updated_at of the connection table?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too was copied verbatim from the existing implementation. See my comments above about a follow-up PR.

@colesnodgrass colesnodgrass temporarily deployed to more-secrets October 10, 2022 20:58 Inactive
Copy link
Contributor

@benmoriceau benmoriceau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense about the files that got moved.

@colesnodgrass colesnodgrass merged commit d30de1b into master Oct 11, 2022
@colesnodgrass colesnodgrass deleted the cole/mirco-metrics-reporter branch October 11, 2022 16:13
malikdiarra added a commit that referenced this pull request Oct 13, 2022
malikdiarra added a commit that referenced this pull request Oct 13, 2022
* Revert "improve query performance (#17862)"

This reverts commit e0db09b.

* Revert "fix metric reporter not producing metrics (#17863)"

This reverts commit 63e39e6.

* Revert "convert airbyte-metrics-reporter to micronaut (#17365)"

This reverts commit d30de1b.
jhammarstedt pushed a commit to jhammarstedt/airbyte that referenced this pull request Oct 31, 2022
* sealed class experiment

* micronaut the metric reporter service

* code format

* move event-listeners to EventListeners class

* code format

* db cleanup; start adding tests

* finish porting over MetricsQueriesTest pieces that apply

* dedupe/simplify test code

* add EmitterTest; misc code clean-up

* address pmd warnings

* remove code that was moved to the reporter package

* update application.yml

* Emitter[] -> List<Emitter>

* remove unused singleton

* formatting

* formatting

* remove default test creds

* update banner

* remove commented out code

* remove another commented out line
jhammarstedt pushed a commit to jhammarstedt/airbyte that referenced this pull request Oct 31, 2022
* Revert "improve query performance (airbytehq#17862)"

This reverts commit e0db09b.

* Revert "fix metric reporter not producing metrics (airbytehq#17863)"

This reverts commit 63e39e6.

* Revert "convert airbyte-metrics-reporter to micronaut (airbytehq#17365)"

This reverts commit d30de1b.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants