Skip to content

Commit

Permalink
feat: add option to configure dataPlaneUrl as the metrics url (#471)
Browse files Browse the repository at this point in the history
* feat: add option to configure `dataPlaneUrl` as the metrics url

* chore: bump the metrics module version

Both rudderreporter and gsonrudderadapter.
  • Loading branch information
1abhishekpandey authored Aug 27, 2024
1 parent 369dede commit f0d3ef1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
8 changes: 3 additions & 5 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ dependencies {
implementation 'androidx.annotation:annotation:1.6.0'


implementation 'com.rudderstack.android.sdk:rudderreporter:[0.4.0, 0.6.0)'
// implementation(project(path: ':rudderreporter'))
// implementation(project(path: ':gsonrudderadapter'))
implementation 'com.rudderstack.kotlin.sdk:gsonrudderadapter:[0.2.0, 0.3.0)'
implementation 'com.rudderstack.android.sdk:rudderreporter:0.6.0'
implementation 'com.rudderstack.kotlin.sdk:gsonrudderadapter:0.2.0'

// required for new life cycle methods
compileOnly 'androidx.lifecycle:lifecycle-process:2.6.1'
Expand Down Expand Up @@ -89,4 +87,4 @@ tasks.withType(JavaExec) {
//apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

apply from: rootProject.file('gradle/mvn-publish.gradle')
apply from: rootProject.file('gradle/codecov.gradle')
apply from: rootProject.file('gradle/codecov.gradle')
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void initiateRudderReporterFromPrefetchedConfig() {
if (serverConfig != null && serverConfig.source != null
&& serverConfig.source.sourceConfiguration != null) {
RudderLogger.logDebug("EventRepository: constructor: Prefetched source serverConfig is available");
enableStatsCollection(application, writeKey, serverConfig.source.sourceConfiguration.getStatsCollection());
enableStatsCollection(application, writeKey, serverConfig.source.sourceConfiguration.getStatsCollection(), dataResidencyManager.getDataPlaneUrl());
} else {
RudderLogger.logDebug("EventRepository: constructor: Prefetched source serverConfig is not available");
}
Expand Down Expand Up @@ -271,8 +271,6 @@ private void initiateSDK(@Nullable RudderConsentFilter consentFilter) {
if (serverConfig != null) {
isSDKEnabled = serverConfig.source.isSourceEnabled;
if (isSDKEnabled) {
if (serverConfig.source.sourceConfiguration != null)
enableStatsCollection(application, writeKey, serverConfig.source.sourceConfiguration.getStatsCollection());
dataResidencyManager.setDataResidencyUrls(serverConfig);
dataPlaneUrl = dataResidencyManager.getDataPlaneUrl();
if (dataPlaneUrl == null) {
Expand All @@ -281,6 +279,8 @@ private void initiateSDK(@Nullable RudderConsentFilter consentFilter) {
Collections.singletonMap(LABEL_TYPE, LABEL_TYPE_DATA_PLANE_URL_INVALID));
return;
}
if (serverConfig.source.sourceConfiguration != null)
enableStatsCollection(application, writeKey, serverConfig.source.sourceConfiguration.getStatsCollection(), dataPlaneUrl);
if (consentFilter != null)
this.consentFilterHandler = new ConsentFilterHandler(serverConfig.source, consentFilter);
cloudModeManager.startCloudModeProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ private ReportManager() {
private static final String FLUSH_WORKER_INIT_COUNTER_TAG = "flush_worker_init";
private static final String ENCRYPTED_DB_COUNTER_TAG = "db_encrypt";

private static final String METRICS_URL_DEV = "https://sdk-metrics.dev-rudder.rudderlabs.com/";
private static final String METRICS_URL_PROD = "https://sdk-metrics.rudderstack.com/";
private static Metrics metrics = null;
private static ErrorClient errorStatsClient = null;

Expand Down Expand Up @@ -161,15 +159,15 @@ private static void incrementCounter(LongCounter counter, int value) {

@SuppressWarnings("ConstantConditions")
static void enableStatsCollection(Application application, String writeKey,
@NonNull SourceConfiguration.StatsCollection statsCollection) {
@NonNull SourceConfiguration.StatsCollection statsCollection, String dataPlaneUrl) {
if (!isStatsReporterAvailable()) {
if (!(statsCollection.getMetrics().isEnabled() || statsCollection.getErrors().isEnabled())) {
RudderLogger.logDebug("EventRepository: Stats collection is not enabled");
return;
}
RudderLogger.logDebug("EventRepository: Creating Stats Reporter");
initiateRudderReporter(application, writeKey, statsCollection.getMetrics().isEnabled(),
statsCollection.getErrors().isEnabled());
statsCollection.getErrors().isEnabled(), dataPlaneUrl);
RudderLogger.logDebug("EventRepository: Metrics collection is not initialized");
return;
}
Expand Down Expand Up @@ -211,10 +209,10 @@ private static void checkAndUpdateErrorsCollection(boolean isErrorsEnabled) {
}

private static void initiateRudderReporter(Context context, @Nullable String writeKey,
boolean isMetricsEnabled, boolean isErrorsEnabled) {
boolean isMetricsEnabled, boolean isErrorsEnabled, String dataPlaneUrl) {
RudderLogger.logDebug("EventRepository: Creating RudderReporter isMetricsEnabled: " + isMetricsEnabled + " isErrorsEnabled: " + isErrorsEnabled);
if (rudderReporter == null) {
rudderReporter = new DefaultRudderReporter(context, METRICS_URL_PROD,
rudderReporter = new DefaultRudderReporter(context, dataPlaneUrl,
getStatsConfig(writeKey), new GsonAdapter(), isMetricsEnabled, isErrorsEnabled);
rudderReporter.getSyncer().startScheduledSyncs(METRICS_UPLOAD_INTERVAL,
true, METRICS_FLUSH_COUNT);
Expand Down

0 comments on commit f0d3ef1

Please sign in to comment.