From 3ea3869438e456b26e8d7b348e14715d6dd92597 Mon Sep 17 00:00:00 2001 From: bhashinee Date: Thu, 7 Nov 2024 10:32:17 +0530 Subject: [PATCH] Update the API list generation logic --- .../metric/handler/MetricHandler.java | 20 ++++++------------- .../initializer/ServiceBusInitializer.java | 6 +++--- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/components/mediation/data-publishers/org.wso2.micro.integrator.observability/src/main/java/org/wso2/micro/integrator/observability/metric/handler/MetricHandler.java b/components/mediation/data-publishers/org.wso2.micro.integrator.observability/src/main/java/org/wso2/micro/integrator/observability/metric/handler/MetricHandler.java index 898bee9580..7cfccd57dd 100644 --- a/components/mediation/data-publishers/org.wso2.micro.integrator.observability/src/main/java/org/wso2/micro/integrator/observability/metric/handler/MetricHandler.java +++ b/components/mediation/data-publishers/org.wso2.micro.integrator.observability/src/main/java/org/wso2/micro/integrator/observability/metric/handler/MetricHandler.java @@ -312,8 +312,9 @@ private void incrementInboundEndpointErrorCount(String name) { */ private String getApiName(String contextPath, MessageContext synCtx) { Collection apiList = synCtx.getEnvironment().getSynapseConfiguration().getAPIs(); - Collection withVersionsApiList = getVersionsApiList(apiList); - Collection defaultApiList = getDefaultApiList(apiList); + Collection withVersionsApiList = new ArrayList<>(); + Collection defaultApiList = new ArrayList<>(); + updateApiLists(apiList, withVersionsApiList, defaultApiList); if (!withVersionsApiList.isEmpty()) { String apiName = getResolvedApiName(contextPath, synCtx, withVersionsApiList); if (apiName != null) { @@ -340,24 +341,15 @@ private static String getResolvedApiName(String contextPath, MessageContext synC return apiName; } - private Collection getVersionsApiList(Collection apiList) { - Collection withVersionsApiList = new ArrayList<>(); + private void updateApiLists(Collection apiList, Collection withVersionsApiList, + Collection defaultApiList) { for (API api : apiList) { if (StringUtils.isNotBlank(api.getVersionStrategy().getVersion())) { withVersionsApiList.add(api); - } - } - return withVersionsApiList; - } - - private Collection getDefaultApiList(Collection apiList) { - Collection defaultApiList = new ArrayList<>(); - for (API api : apiList) { - if (!StringUtils.isNotBlank(api.getVersionStrategy().getVersion())) { + } else { defaultApiList.add(api); } } - return defaultApiList; } /** diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/ServiceBusInitializer.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/ServiceBusInitializer.java index 529ca9fafc..4426a4d75f 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/ServiceBusInitializer.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/ServiceBusInitializer.java @@ -172,10 +172,10 @@ protected void activate(ComponentContext ctxt) { } SynapseEnvironment synapseEnvironment = contextInfo.getSynapseEnvironment(); List handlers = synapseEnvironment.getSynapseHandlers(); - if (System.getProperty(ServiceBusConstants.ENABLE_PROMETHEUS_API_PROPERTY) != null - && System.getProperty(ServiceBusConstants.ENABLE_PROMETHEUS_API_PROPERTY).equals("false")) { + String prometheusApiEnabled = System.getProperty(ServiceBusConstants.ENABLE_PROMETHEUS_API_PROPERTY); + if ("false".equals(prometheusApiEnabled)) { handlers.remove(handlers.stream().filter(c -> c instanceof MetricHandler).findFirst().orElse(null)); - } else { + } else if ("true".equals(prometheusApiEnabled)) { if (!handlers.stream().anyMatch(c -> c instanceof MetricHandler)) { handlers.add(new MetricHandler()); }