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

Update AnalyticsDataPublisher to Handle Multiple Reporter Types #12580

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public class Constants {
public static final String USERNAME_MASK_VALUE = "*****";

public static final String AUTH_API_URL = "auth.api.url";

public static final String CHOREO_REPORTER_NAME = "choreo";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
import org.wso2.carbon.apimgt.common.analytics.Constants;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.wso2.carbon.apimgt.common.analytics.Constants.CHOREO_REPORTER_NAME;

/**
* Analytics event publisher for APIM.
*/
Expand All @@ -53,6 +56,16 @@ public static AnalyticsDataPublisher getInstance() {
return instance;
}

private List<String> getReporterTypesOrNull(String typeConfig) {
if (typeConfig == null || typeConfig.isEmpty()) {
return null;
}
return Arrays.stream(typeConfig.replaceAll("[\\[\\]]", "").split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
}

private List<String> getReportersClassesOrNull(Map<String, String> configs) {
List<String> reporterClasses = new ArrayList<>();
List<String> reporterKeys = configs.keySet()
Expand Down Expand Up @@ -93,7 +106,7 @@ private List<CounterMetric> getSuccessOrFaultyCounterMetrics(List<MetricReporter
public void initialize(AnalyticsCommonConfiguration commonConfig) {
Map<String, String> configs = commonConfig.getConfigurations();
String reporterClass = configs.get("publisher.reporter.class");
String reporterType = configs.get("type");
List<String> reporterTypes = getReporterTypesOrNull(configs.get("type"));
List<String> reporterClasses = getReportersClassesOrNull(configs);
try {
List<MetricReporter> metricReporters = new ArrayList<>();
Expand All @@ -113,9 +126,21 @@ public void initialize(AnalyticsCommonConfiguration commonConfig) {
" out of multiple metric reporters.", e);
}
}
} else if (reporterType != null && !reporterType.equals("")) {
metricReporter = MetricReporterFactory.getInstance().createLogMetricReporter(configs);
metricReporters.add(metricReporter);
} else if (reporterTypes != null && !reporterTypes.isEmpty()) {
for (String type : reporterTypes) {
if (type.equals(CHOREO_REPORTER_NAME)) {
String authEndpoint = configs.get(Constants.AUTH_API_URL);
if (authEndpoint == null || authEndpoint.isEmpty()) {
throw new MetricCreationException("Analytics Config Endpoint is not provided.");
}
metricReporter = MetricReporterFactory.getInstance().createMetricReporter(configs);
metricReporters.add(metricReporter);
} else {
metricReporter = MetricReporterFactory.getInstance().createLogMetricReporter(configs);
metricReporters.add(metricReporter);
}

}
} else {
String authEndpoint = configs.get(Constants.AUTH_API_URL);

Expand Down
Loading