Class PrometheusResultProcessor

java.lang.Object
org.tailormap.api.prometheus.PrometheusResultProcessor
All Implemented Interfaces:
TagNames

@Component public class PrometheusResultProcessor extends Object implements TagNames
  • Constructor Details

    • PrometheusResultProcessor

      public PrometheusResultProcessor()
  • Method Details

    • processPrometheusResultsForApplications

      public Collection<Map<String,String>> processPrometheusResultsForApplications(com.fasterxml.jackson.databind.JsonNode root)
      Processes the JSON response from a Prometheus query and groups the results by TagNames.METRICS_APP_ID_TAG. Each appId will have a map of metrics, where the key is the metric type (e.g., "total", "lastUpdated") and the value is the metric value. Additionally, the appName is included in the map for each appId.
      Parameters:
      root - the root JSON node containing the Prometheus query results (expected structure: root.data.result) where each result has a "metric" object with "appId", "type", and "value" fields, and a "value" array where the second element is the metric value. The "metric" object may also contain "appName".
      Returns:
      a map where the key is the appId and the value is another map containing metric types as keys and their corresponding values. The inner map also includes the appName under the key "appName". If an appId has no metrics, it will not be included in the results.
      See Also:
    • processPrometheusResultsForApplicationLayers

      public Collection<Map<String,String>> processPrometheusResultsForApplicationLayers(com.fasterxml.jackson.databind.JsonNode root)
      Processes the JSON response from a Prometheus query and groups the results by TagNames.METRICS_APP_LAYER_ID_TAG. Each appLayerId will have a map of metrics, where the key is the metric type (e.g., "total", "lastUpdated") and the value is the metric value. Additionally, the appName is included in the map for each appId.
      Parameters:
      root - the root JSON node containing the Prometheus query results (expected structure: root.data.result) where each result has a "metric" object with "appId", "type", and "value" fields, and a "value" array where the second element is the metric value. The "metric" object may also contain "appName".
      Returns:
      a map where the key is the appLayerId and the value is another map containing metric types as keys and their corresponding values. The inner map also includes the appName under the key "appName". If an appId has no metrics, it will not be included in the results.
      See Also:
    • processPrometheusResultsToJsonArray

      public com.fasterxml.jackson.databind.node.ArrayNode processPrometheusResultsToJsonArray(com.fasterxml.jackson.databind.JsonNode jsonResponse1, com.fasterxml.jackson.databind.JsonNode jsonResponse2) throws IOException
      Merges two Prometheus JSON responses and processes the results into an ArrayNode. Each appId will have a map of metrics, where the key is the metric type (e.g., "total", "lastUpdated") and the value is the metric value.
      Parameters:
      jsonResponse1 - the first JSON response from a Prometheus query
      jsonResponse2 - the second JSON response from a Prometheus query
      Returns:
      an ArrayNode containing maps of metrics for each appId
      Throws:
      IOException - if there is an error processing the JSON responses