YolandaMDavis commented on a change in pull request #4156: NIFI-7273: Add flow
metrics REST endpoint with for Prometheus scraping
URL: https://github.com/apache/nifi/pull/4156#discussion_r403068355
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
##########
@@ -381,6 +388,66 @@ public Response getFlow(
return generateOkResponse(entity).build();
}
+ /**
+ * Retrieves the metrics of the entire flow.
+ *
+ * @return A flowMetricsEntity.
+ * @throws InterruptedException if interrupted
+ */
+ @GET
+ @Consumes(MediaType.WILDCARD)
+ @Produces(MediaType.WILDCARD)
+ @Path("metrics/{producer}")
+ @ApiOperation(
+ value = "Gets all metrics for the flow from a particular node",
+ response = StreamingOutput.class,
+ authorizations = {
+ @Authorization(value = "Read - /flow")
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(code = 400, message = "NiFi was unable to
complete the request because it was invalid. The request should not be retried
without modification."),
+ @ApiResponse(code = 401, message = "Client could not be
authenticated."),
+ @ApiResponse(code = 403, message = "Client is not
authorized to make this request."),
+ @ApiResponse(code = 404, message = "The specified resource
could not be found."),
+ @ApiResponse(code = 409, message = "The request was valid
but NiFi was not in the appropriate state to process it. Retrying the same
request later may be successful.")
+ }
+ )
+ public Response getFlowMetrics(
+ @ApiParam(
+ value = "The producer for flow file metrics. Each producer
may have its own output format.",
+ required = true
+ )
+ @PathParam("producer") final String producer) throws
InterruptedException {
+
+ authorizeFlow();
+
+ if ("prometheus".equalsIgnoreCase(producer)) {
+ // get this process group flow
+ serviceFacade.generateFlowMetrics();
+ // generate a streaming response
+ final StreamingOutput response = output -> {
+ Writer writer = new BufferedWriter(new
OutputStreamWriter(output));
+ for (CollectorRegistry collectorRegistry :
PrometheusMetricsUtil.ALL_REGISTRIES) {
+ TextFormat.write004(writer,
collectorRegistry.metricFamilySamples());
+ // flush the response
+ output.flush();
+ }
+ writer.flush();
+ writer.close();
+ };
+
+ String generatedFilename = "flowMetrics_" +
System.currentTimeMillis();
+ return generateOkResponse(response)
+ .type(MediaType.TEXT_PLAIN_TYPE)
+ .header("Content-Disposition", String.format("attachment;
filename=\"%s\"", generatedFilename))
Review comment:
@mattyb149 this line (along with line 441) isn't needed (it's causing the
metrics be be downloaded as a file vs visible in a browser). Prometheus works
fine with it however it may cause an issue for others attempting to simply view
metrics
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services