-
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
fix loading remote definitions via cron #21410
Conversation
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.
👍
Just to check my understanding - in Cloud, there will be a PR to call definitionsProvider.loadDefinitions()
?
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.
I am wondering if we could leverage micronaut caching here instead of requiring the client to decide when to actually load the definitions. I added comments trying to highlight what this could look like.
edit: link to micronaut doc
The other missing piece would be updating the application.yml
with:
micronaut:
caches:
remoteDefinitions:
charset: 'UTF-8'
expire-after-write: 1min
@jdpgrailsdev, do you think that would be a valid approach to manage how frequently we refresh definitions?
this.destinationDefinitions = parseDefinitions(this.seedResourceClass, SeedType.STANDARD_DESTINATION_DEFINITION.getResourcePath(), | ||
SeedType.DESTINATION_SPEC.getResourcePath(), SeedType.STANDARD_DESTINATION_DEFINITION.getIdName(), SeedType.DESTINATION_SPEC.getIdName(), | ||
StandardDestinationDefinition.class); | ||
public void loadDefinitions() { |
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.
Since local definitions are read from the resources, we could annotate here with @PostConstruct
@@ -48,22 +48,26 @@ public LocalDefinitionsProvider(final Class<?> seedResourceClass) throws IOExcep | |||
this.seedResourceClass = seedResourceClass; | |||
|
|||
// TODO remove this call once dependency injection framework manages object creation | |||
initialize(); | |||
loadDefinitions(); |
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.
We do not need this call here.
StandardDestinationDefinition::getDestinationDefinitionId, | ||
destination -> destination.withProtocolVersion( | ||
AirbyteProtocolVersion.getWithDefault(destination.getSpec() != null ? destination.getSpec().getProtocolVersion() : null).serialize()))); | ||
public void loadDefinitions() { |
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.
Add a @cACHEpUT("remoteDefinitions") annotation here instead of @PostConstruct
all the getters in this provider should call loadDefinitions()
airbyte-config/init/src/main/java/io/airbyte/config/init/ApplyDefinitionsHelper.java
Outdated
Show resolved
Hide resolved
airbyte-config/init/src/main/java/io/airbyte/config/init/DefinitionsProvider.java
Outdated
Show resolved
Hide resolved
@gosusnp Yes, but I think it is a little more involved. The Micronaut Cache abstraction is just that -- an abstraction over the creation and management of an in memory cache, such as one you could create using Guava, Ehcache or Caffeine. You would still need to mark the methods that will cache their return values with the |
Ok! Moved to using micronaut to handle the caching and reverted to the previous interface. Set to cache for 15s (cron runs every 30s). |
@jdpgrailsdev, I agree, it is a restriction from having an in-memory cache, I don't think it is a blocker for the current use case. The goal is to refresh frequently and I don't think we want to have concurrent updates so it should remain restricted to a single instance. |
|
What
fixes #21401
After #21073 moved the definitions provider to be injected as a singleton, the behavior of only fetching definitions in the RemoteDefinitionProvider on class initialization meant that we were no longer fetching the latest definitions each time the cron ran.
How
Refactor the RemoteDefinitionsProvider to let use leverage micronaut caching to determine when to re-fetch the data. Each getter now calls the method to fetch the data, but we're caching the results of the method for 15s on airbyte-cron.