try { String asUser = WSUtils.getUserFromSecurityContext(securityContext); return Pair.of(c, metricsService.getComponentStats(topology, c, from, to, asUser)); } catch (IOException e) { throw new RuntimeException(e);
@GET @Path("/topologies/{id}/components/{topologyComponentId}/component_stats") @Timed public Response getComponentStats(@PathParam("id") Long id, @PathParam("topologyComponentId") Long topologyComponentId, @QueryParam("from") Long from, @QueryParam("to") Long to, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, id, READ); assertTimeRange(from, to); Topology topology = catalogService.getTopology(id); TopologyComponent topologyComponent = catalogService.getTopologyComponent(id, topologyComponentId); if (topology != null && topologyComponent != null) { String asUser = WSUtils.getUserFromSecurityContext(securityContext); TopologyTimeSeriesMetrics.TimeSeriesComponentMetric metrics = metricsService.getComponentStats(topology, topologyComponent, from, to, asUser); return WSUtils.respondEntity(metrics, OK); } else if (topology == null) { throw EntityNotFoundException.byId("Topology: " + id.toString()); } else { // topologyComponent == null throw EntityNotFoundException.byId("TopologyComponent: " + id.toString()); } }
.map(Unchecked.function(s -> { ComponentMetricSummary overviewMetric; TopologyTimeSeriesMetrics.TimeSeriesComponentMetric currentMetric = metricsService.getComponentStats(topology, s, from, to, asUser); TopologyTimeSeriesMetrics.TimeSeriesComponentMetric previousMetric = metricsService.getComponentStats(topology, s, from - (to - from), from - 1, asUser); if (clazz.equals(TopologySource.class)) { overviewMetric = ComponentMetricSummary.convertSourceMetric(
TopologyTimeSeriesMetrics.TimeSeriesComponentMetric currentMetric = metricsService.getComponentStats(topology, component, from, to, asUser); TopologyTimeSeriesMetrics.TimeSeriesComponentMetric previousMetric = metricsService.getComponentStats(topology, component, from - (to - from), from - 1, asUser); if (clazz.equals(TopologySource.class)) { overviewMetric = ComponentMetricSummary.convertSourceMetric(currentMetric, previousMetric);