Class PrometheusResultProcessor

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

public class PrometheusResultProcessor extends Object implements TagNames
  • Constructor Details

    • PrometheusResultProcessor

      public PrometheusResultProcessor()
  • Method Details

    • processPrometheusResults

      public Map<String,Map<String,String>> processPrometheusResults(com.fasterxml.jackson.databind.JsonNode root)
      Processes the JSON response from a Prometheus query and groups the results by appId. 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.
    • processPrometheusResults

      public Map<String,Map<String,String>> processPrometheusResults(String jsonResponse) throws com.fasterxml.jackson.core.JsonProcessingException
      Processes the JSON response from a Prometheus query and groups the results by appId. This method is a convenience wrapper around processPrometheusResults(JsonNode).
      Parameters:
      jsonResponse - the JSON response string from a Prometheus query
      Returns:
      a map where the key is the appId and the value is another map containing metric types as keys and their corresponding values.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if there is an error parsing the JSON response
    • 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