From f8e3b9ebacb4d927ac6a4f9a3fee0eaaf2d9fd36 Mon Sep 17 00:00:00 2001 From: "Yolanda M. Davis" Date: Wed, 2 Aug 2023 20:33:18 -0400 Subject: [PATCH] NIFI-11899 Correct Bulletin Metrics Registry to return latest Bulletins This closes #7567 Signed-off-by: David Handermann --- .../nifi/web/StandardNiFiServiceFacade.java | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java index 09038d0707..7daff3469a 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java @@ -438,29 +438,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { private AuthorizableLookup authorizableLookup; // Prometheus Metrics objects - private final NiFiMetricsRegistry nifiMetricsRegistry = new NiFiMetricsRegistry(); private final JvmMetricsRegistry jvmMetricsRegistry = new JvmMetricsRegistry(); private final ConnectionAnalyticsMetricsRegistry connectionAnalyticsMetricsRegistry = new ConnectionAnalyticsMetricsRegistry(); - private final BulletinMetricsRegistry bulletinMetricsRegistry = new BulletinMetricsRegistry(); private final ClusterMetricsRegistry clusterMetricsRegistry = new ClusterMetricsRegistry(); - private final Collection configuredRegistries = Arrays.asList( - nifiMetricsRegistry, - jvmMetricsRegistry, - connectionAnalyticsMetricsRegistry, - bulletinMetricsRegistry, - clusterMetricsRegistry - ); - - private final Collection metricsRegistries = Arrays.asList( - nifiMetricsRegistry.getRegistry(), - jvmMetricsRegistry.getRegistry(), - connectionAnalyticsMetricsRegistry.getRegistry(), - bulletinMetricsRegistry.getRegistry(), - clusterMetricsRegistry.getRegistry() - ); - - // ----------------------------------------- // Synchronization methods // ----------------------------------------- @@ -6038,12 +6019,14 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { return entityFactory.createProcessorDiagnosticsEntity(dto, revisionDto, permissionsDto, processorStatusDto, bulletins); } - @Override - public Collection generateFlowMetrics() { + protected Collection populateFlowMetrics() { + // Include registries which are fully refreshed upon each invocation + NiFiMetricsRegistry nifiMetricsRegistry = new NiFiMetricsRegistry(); + BulletinMetricsRegistry bulletinMetricsRegistry = new BulletinMetricsRegistry(); + final String instanceId = StringUtils.isEmpty(controllerFacade.getInstanceId()) ? "" : controllerFacade.getInstanceId(); ProcessGroupStatus rootPGStatus = controllerFacade.getProcessGroupStatus("root"); - nifiMetricsRegistry.clear(); PrometheusMetricsUtil.createNifiMetrics(nifiMetricsRegistry, rootPGStatus, instanceId, "", ROOT_PROCESS_GROUP, PrometheusMetricsUtil.METRICS_STRATEGY_COMPONENTS.getValue()); @@ -6142,10 +6125,24 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { final boolean isClustered = clusterCoordinator != null; final boolean isConnectedToCluster = isClustered() && clusterCoordinator.isConnected(); PrometheusMetricsUtil.createClusterMetrics(clusterMetricsRegistry, instanceId, isClustered, isConnectedToCluster, connectedNodesLabel, connectedNodeCount, totalNodeCount); + Collection metricsRegistries = Arrays.asList( + nifiMetricsRegistry, + jvmMetricsRegistry, + connectionAnalyticsMetricsRegistry, + bulletinMetricsRegistry, + clusterMetricsRegistry + ); return metricsRegistries; } + @Override + public Collection generateFlowMetrics() { + + return populateFlowMetrics().stream().map(AbstractMetricsRegistry::getRegistry) + .collect(Collectors.toList()); + } + @Override public Collection generateFlowMetrics(final Set includeRegistries) { final Set selectedRegistries = includeRegistries.isEmpty() ? new HashSet<>(Arrays.asList(FlowMetricsRegistry.values())) : includeRegistries; @@ -6154,7 +6151,8 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { .map(FlowMetricsRegistry::getRegistryClass) .collect(Collectors.toSet()); - generateFlowMetrics(); + Collection configuredRegistries = populateFlowMetrics(); + return configuredRegistries.stream() .filter(configuredRegistry -> registryClasses.contains(configuredRegistry.getClass())) .map(AbstractMetricsRegistry::getRegistry)