Skip to content

Commit

Permalink
Enable caching of analytics tracking data (#11667)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpgrailsdev committed Mar 14, 2024
1 parent e461ac4 commit d9eec27
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 7 deletions.
11 changes: 11 additions & 0 deletions airbyte-analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ environment variable. In addition to the type of analytics tracker, the followin
In order to use this module in a service at runtime, add the following configuration to the service's `application.yml` file:

```yaml
micronaut:
caches:
# used by the analytics tracking client to cache calls to resolve the deployment and identity (workspace) for
# track events
analytics-tracking-deployments:
charset: "UTF-8"
expire-after-access: 10m
analytics-tracking-identity:
charset: "UTF-8"
expire-after-access: 10m

airbyte:
deployment-mode: ${DEPLOYMENT_MODE:OSS}
role: ${AIRBYTE_ROLE:dev}
Expand Down
1 change: 1 addition & 0 deletions airbyte-analytics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {

api(libs.segment.java.analytics)
api(libs.micronaut.http)
api(libs.micronaut.cache.caffeine)
api(libs.bundles.micronaut.annotation)
api(libs.bundles.micronaut.kotlin)
api(libs.kotlin.logging)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.segment.analytics.messages.TrackMessage
import io.airbyte.api.client.model.generated.DeploymentMetadataRead
import io.airbyte.api.client.model.generated.WorkspaceRead
import io.github.oshai.kotlinlogging.KotlinLogging
import io.micronaut.cache.annotation.CacheConfig
import io.micronaut.cache.annotation.Cacheable
import io.micronaut.context.annotation.Requires
import io.micronaut.context.annotation.Value
import io.micronaut.http.context.ServerRequestContext
Expand Down Expand Up @@ -337,19 +339,23 @@ class LoggingTrackingClient(
}

@Singleton
class DeploymentFetcher(
@CacheConfig("analytics-tracking-deployments")
open class DeploymentFetcher(
@Named("deploymentSupplier") val deploymentFetcher: Supplier<DeploymentMetadataRead>,
) : Supplier<Deployment> {
@Cacheable
override fun get(): Deployment {
val deploymentMetadata = deploymentFetcher.get()
return Deployment(deploymentMetadata)
}
}

@Singleton
class TrackingIdentityFetcher(
@CacheConfig("analytics-tracking-identity")
open class TrackingIdentityFetcher(
@Named("workspaceFetcher") val workspaceFetcher: Function<UUID, WorkspaceRead>,
) : Function<UUID, TrackingIdentity> {
@Cacheable
override fun apply(workspaceId: UUID): TrackingIdentity {
val workspaceRead = workspaceFetcher.apply(workspaceId)
val email: String? =
Expand Down
1 change: 1 addition & 0 deletions airbyte-api-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
implementation(libs.log4j.slf4j2.impl)
implementation(libs.bundles.jackson)
implementation(libs.bundles.micronaut)
implementation(libs.bundles.micronaut.cache)
implementation(libs.bundles.micronaut.data.jdbc)
implementation(libs.bundles.micronaut.metrics)
implementation(libs.micronaut.jaxrs.server)
Expand Down
12 changes: 12 additions & 0 deletions airbyte-api-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
micronaut:
application:
name: airbyte-api-server
caches:
# used by the analytics tracking client to cache calls to resolve the deployment and identity (workspace) for
# track events
analytics-tracking-deployments:
charset: "UTF-8"
expire-after-access: 10m
analytics-tracking-identity:
charset: "UTF-8"
expire-after-access: 10m
env:
cloud-deduction: true
executors:
Expand Down Expand Up @@ -92,6 +101,9 @@ endpoints:
beans:
enabled: true
sensitive: false
caches:
enabled: true
sensitive: false
env:
enabled: true
sensitive: false
Expand Down
1 change: 1 addition & 0 deletions airbyte-connector-builder-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
implementation(libs.guava)
implementation(platform(libs.micronaut.platform))
implementation(libs.bundles.micronaut)
implementation(libs.bundles.micronaut.cache)
implementation(libs.micronaut.http)
implementation(libs.micronaut.security)
implementation(libs.jakarta.annotation.api)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
micronaut:
application:
name: airbyte-connector-builder-server
caches:
# used by the analytics tracking client to cache calls to resolve the deployment and identity (workspace) for
# track events
analytics-tracking-deployments:
charset: "UTF-8"
expire-after-access: 10m
analytics-tracking-identity:
charset: "UTF-8"
expire-after-access: 10m
env:
cloud-deduction: true
metrics:
Expand Down Expand Up @@ -77,6 +86,9 @@ endpoints:
beans:
enabled: true
sensitive: false
caches:
enabled: true
sensitive: false
env:
enabled: true
sensitive: false
Expand Down
1 change: 1 addition & 0 deletions airbyte-container-orchestrator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies {

implementation(platform(libs.micronaut.platform))
implementation(libs.bundles.micronaut)
implementation(libs.bundles.micronaut.cache)
implementation(libs.bundles.micronaut.metrics)
implementation(libs.guava)
implementation(libs.s3)
Expand Down
12 changes: 12 additions & 0 deletions airbyte-container-orchestrator/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
micronaut:
application:
name: airbyte-container-orchestrator
caches:
# used by the analytics tracking client to cache calls to resolve the deployment and identity (workspace) for
# track events
analytics-tracking-deployments:
charset: "UTF-8"
expire-after-access: 10m
analytics-tracking-identity:
charset: "UTF-8"
expire-after-access: 10m
env:
cloud-deduction: true
server:
Expand Down Expand Up @@ -129,6 +138,9 @@ endpoints:
beans:
enabled: true
sensitive: false
caches:
enabled: true
sensitive: false
env:
enabled: true
sensitive: false
Expand Down
1 change: 1 addition & 0 deletions airbyte-cron/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {

implementation(platform(libs.micronaut.platform))
implementation(libs.bundles.micronaut)
implementation(libs.bundles.micronaut.cache)
implementation(libs.bundles.micronaut.metrics)
implementation(libs.bundles.kubernetes.client)
implementation(libs.bundles.temporal)
Expand Down
17 changes: 14 additions & 3 deletions airbyte-cron/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
micronaut:
application:
name: airbyte-cron
caches:
# used by the analytics tracking client to cache calls to resolve the deployment and identity (workspace) for
# track events
analytics-tracking-deployments:
charset: "UTF-8"
expire-after-access: 10m
analytics-tracking-identity:
charset: "UTF-8"
expire-after-access: 10m
remote-definitions-provider:
expire-after-write: 15s
env:
cloud-deduction: true
metrics:
Expand All @@ -12,9 +23,6 @@ micronaut:
step: ${MICROMETER_METRICS_STEP:PT30S}
host: ${STATSD_HOST:localhost}
port: ${STATSD_PORT:8125}
caches:
remote-definitions-provider:
expire-after-write: 15s
server:
port: 9001

Expand Down Expand Up @@ -106,6 +114,9 @@ endpoints:
beans:
enabled: true
sensitive: false
caches:
enabled: true
sensitive: false
env:
enabled: true
sensitive: false
Expand Down
1 change: 1 addition & 0 deletions airbyte-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {

implementation(platform(libs.micronaut.platform))
implementation(libs.bundles.micronaut)
implementation(libs.bundles.micronaut.cache)
implementation(libs.bundles.micronaut.data.jdbc)
implementation(libs.bundles.micronaut.metrics)
implementation(libs.micronaut.jaxrs.server)
Expand Down
12 changes: 12 additions & 0 deletions airbyte-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
micronaut:
application:
name: airbyte-server
caches:
# used by the analytics tracking client to cache calls to resolve the deployment and identity (workspace) for
# track events
analytics-tracking-deployments:
charset: "UTF-8"
expire-after-access: 10m
analytics-tracking-identity:
charset: "UTF-8"
expire-after-access: 10m
env:
cloud-deduction: true
executors:
Expand Down Expand Up @@ -344,6 +353,9 @@ endpoints:
beans:
enabled: true
sensitive: false
caches:
enabled: true
sensitive: false
env:
enabled: true
sensitive: false
Expand Down
2 changes: 1 addition & 1 deletion airbyte-workers/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ dependencies {
implementation(platform(libs.micronaut.platform))
implementation(libs.google.cloud.storage)
implementation(libs.bundles.micronaut)
implementation(libs.bundles.micronaut.cache)
implementation(libs.bundles.micronaut.metrics)
implementation(libs.micronaut.cache.caffeine)
implementation(libs.jooq)
implementation(libs.s3)
implementation(libs.sts)
Expand Down
11 changes: 11 additions & 0 deletions airbyte-workers/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ micronaut:
max-content-length: 52428800 # 50MB
port: 9000
caches:
# used by the analytics tracking client to cache calls to resolve the deployment and identity (workspace) for
# track events
analytics-tracking-deployments:
charset: "UTF-8"
expire-after-access: 10m
analytics-tracking-identity:
charset: "UTF-8"
expire-after-access: 10m
# used by RecordMetricActivity to cache repeated calls to workspaceApi.getWorkspaceByConnectionId.
# entries are UUID connectionIds, so 100,000 entries should be roughly 1.6MB
connection-workspace-id:
Expand Down Expand Up @@ -275,6 +283,9 @@ endpoints:
beans:
enabled: true
sensitive: false
caches:
enabled: true
sensitive: false
env:
enabled: true
sensitive: false
Expand Down
5 changes: 4 additions & 1 deletion deps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ kubernetes-client = "6.5.1"
log4j = "2.22.1"
lombok = "1.18.30"
micronaut = "4.3.5"
micronaut-cache = "4.2.2"
micronaut-data = "4.6.1"
micronaut-email = "2.4.0"
micronaut-jaxrs = "4.3.0"
Expand Down Expand Up @@ -184,7 +185,8 @@ vault-java-driver = { module = "com.bettercloud:vault-java-driver", version = "5

# Micronaut-related dependencies
h2-database = { module = "com.h2database:h2", version = "2.2.224" }
micronaut-cache-caffeine = { module = "io.micronaut.cache:micronaut-cache-caffeine", version = "4.2.2" }
micronaut-cache-caffeine = { module = "io.micronaut.cache:micronaut-cache-caffeine", version.ref = "micronaut-cache" }
micronaut-cache-management = { module = "io.micronaut.cache:micronaut-cache-management", version.ref = "micronaut-cache" }
micronaut-data-connection = { module = "io.micronaut.data:micronaut-data-connection", version.ref = "micronaut-data" }
micronaut-data-processor = { module = "io.micronaut.data:micronaut-data-processor", version.ref = "micronaut-data" }
micronaut-data-jdbc = { module = "io.micronaut.data:micronaut-data-jdbc", version.ref = "micronaut-data" }
Expand Down Expand Up @@ -238,6 +240,7 @@ micronaut = ["jakarta-annotation-api", "jakarta-transaction-api", "micronaut-htt
micronaut-light = ["jakarta-annotation-api", "micronaut-inject-java", "micronaut-runtime"]
micronaut-annotation = ["jakarta-annotation-api", "micronaut-inject-java", "micronaut-inject-kotlin"]
micronaut-annotation-processor = ["micronaut-inject-java", "micronaut-management", "micronaut-validation", "micronaut-data-processor", "micronaut-jaxrs-processor", "micronaut-http-validation"]
micronaut-cache = ["micronaut-cache-caffeine", "micronaut-cache-management"]
micronaut-data-jdbc = [ "micronaut-data-connection", "micronaut-data-jdbc", "micronaut-data-model", "micronaut-data-tx", "jakarta-persistence-api", "micronaut-jdbc-hikari"]
micronaut-email = ["micronaut-email", "micronaut-email-sendgrid"]
micronaut-kotlin = ["micronaut-kotlin-extension-functions", "micronaut-kotlin-runtime"]
Expand Down

0 comments on commit d9eec27

Please sign in to comment.