{
  "openapi": "3.0.1",
  "info": {
    "title": "Metric API Service",
    "description": "Metric API service for posting timeseries, fetching and forecasting timeseries",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "/metrics/api"
    }
  ],
  "tags": [
    {
      "name": "Metrics",
      "description": "API for posting, fetching and forecasting timeseries"
    }
  ],
  "paths": {
    "/1.0/metrics": {
      "get": {
        "tags": [
          "Metrics"
        ],
        "summary": "Get metrics for learning and analysis",
        "description": "Data is fetched according to values provided",
        "operationId": "getMetricTimeSeries",
        "parameters": [
          {
            "name": "X-TenantID",
            "in": "header",
            "description": "The tenant ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "resource",
            "in": "query",
            "description": "The resource name",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "The group name",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "metric",
            "in": "query",
            "description": "The metric name",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "startTime",
            "in": "query",
            "description": "The first time period of the time series to return",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "endTime",
            "in": "query",
            "description": "The last time period of the time series to return",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OkTimedResponse"
                }
              }
            }
          },
          "400": {
            "description": "The request contained invalid parameters and could not be processed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Metrics"
        ],
        "summary": "Post metrics for learning and analysis",
        "description": "Data posted will be analyzed with AI for Anomaly Detection and Forecasting",
        "operationId": "postMetrics",
        "parameters": [
          {
            "name": "X-TenantID",
            "in": "header",
            "description": "The tenant ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "The collection of metrics",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IOAGroupList"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MetricPersistResponse"
                }
              }
            }
          },
          "400": {
            "description": "The request contained invalid parameters and could not be processed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-codegen-request-body-name": "body"
      }
    },
    "/1.0/forecast": {
      "get": {
        "tags": [
          "Metrics"
        ],
        "summary": "Forecast a metric",
        "description": "Data is fetched according to values provided",
        "operationId": "forecastMetricTimeSeries",
        "parameters": [
          {
            "name": "X-TenantID",
            "in": "header",
            "description": "The tenant ID",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "resource",
            "in": "query",
            "description": "The resource name",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "The group name",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "metric",
            "in": "query",
            "description": "The metric name",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "stepsAhead",
            "in": "query",
            "description": "The number of intervals to forecast. Defaults to 24 or half the size of the data - whichever is smallest, unless aggregationInterval is specified",
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "confidence",
            "in": "query",
            "description": "A percentage expressed as a number between 0 and 1 that expresses the confidence that forecasted values will appear within the confidence interval. Default is 0.95",
            "schema": {
              "type": "number",
              "format": "double"
            }
          },
          {
            "name": "aggregationInterval",
            "in": "query",
            "description": "If specified, will aggregate the data to this interval (specified in milliseconds), and then forecast based on it",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "anomalyOnly",
            "in": "query",
            "description": "If specified, will forecast solely based on the last anomalous area",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "batsOnly",
            "in": "query",
            "description": "If specified, will only use the BATS forecasting algorithm, otherwise all algorithms are used",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OkTimedResponse"
                }
              }
            }
          },
          "400": {
            "description": "The request contained invalid parameters and could not be processed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MetricPersistResponse": {
        "type": "object",
        "properties": {
          "_executionTime": {
            "type": "integer",
            "description": "The entire time taken, in milliseconds, to process the request, once received",
            "format": "int64",
            "readOnly": true,
            "example": 200
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "_error": {
            "$ref": "#/components/schemas/_error"
          }
        }
      },
      "_error": {
        "type": "object",
        "properties": {
          "level": {
            "type": "string",
            "description": "The error level",
            "enum": [
              "error"
            ]
          },
          "message": {
            "type": "string",
            "description": "Indicates the nature of the error",
            "example": "Unable to process entity body"
          },
          "description": {
            "type": "string",
            "description": "A more detailed description of the error condition may appear here",
            "example": "Unexpected char 100 at (line no=1, column no=1, offset=0)"
          }
        }
      },
      "IOAGroup": {
        "required": [
          "attributes",
          "metrics",
          "resourceID",
          "timestamp"
        ],
        "type": "object",
        "properties": {
          "timestamp": {
            "type": "string",
            "example": 1672531200000,
            "description": "The time the event occurred, in milliseconds from epoch or ISO8601: yyyy-MM-dd'T'HH:mm:ss.SSSX"
          },
          "resourceID": {
            "type": "string",
            "example": "myServerName eth0",
            "description": "The resource being measured - maxlength 500 chars"
          },
          "tenantID": {
            "type": "string",
            "example": "cfd95b7e-3bc7-4006-a4a8-a73a79c71255",
            "description": "The tenant - for backwards compatibility - typically either specified in REST header or the Kafka key"
          },
          "metrics": {
            "type": "object",
            "additionalProperties": {
              "type": "number",
              "format": "double"
            },
            "example": {
              "bytesIn": 126700,
              "bytesOut": 45921
            },
            "description": "Metric names paired with metric values"
          },
          "attributes": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "example": {
              "group": "NetworkMetrics",
              "node": "myServerName"
            },
            "description": "Attributes of the group of metrics"
          }
        },
        "description": "Contains properties of an IOA style metric grouping"
      },
      "IOAGroupList": {
        "required": [
          "groups"
        ],
        "type": "object",
        "properties": {
          "groups": {
            "type": "array",
            "description": "A collection of groups",
            "items": {
              "$ref": "#/components/schemas/IOAGroup"
            }
          }
        },
        "description": "A list of IOAGroup"
      },
      "OkTimedResponse": {
        "type": "object",
        "properties": {
          "_executionTime": {
            "type": "integer",
            "description": "The entire time taken, in milliseconds, to process the request, once received",
            "format": "int64",
            "readOnly": true,
            "example": 200
          }
        }
      }
    }
  }
}
