openapi: 3.0.1
info:
  title: Metrics service
  contact:
    name: co.brick
    url: https://cobrick.com
    email: aiops@cobrick.com
  license:
    name: Commercial
    url: https://cobrick.com
  version: v1
servers:
  - url: https://app.observe.digital/api/v1
    description: Production environment
  - url: https://stage.observe.digital/api/v1
    description: Staging environment
  - url: http://localhost:8080
    description: Local environment
paths:
  /metrics:
    get:
      tags:
        - metrics
      summary: Get metrics for given parameters
      operationId: getMetrics
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Tenant header
          schema:
            type: string
        - name: startTimestamp
          in: query
          description: From
          required: true
          schema:
            minimum: 0
            type: integer
            format: int64
        - name: endTimestamp
          in: query
          description: To
          required: true
          schema:
            minimum: 0
            type: integer
            format: int64
        - name: namespace
          in: query
          description: Service namespace
          schema:
            type: string
        - name: serviceName
          in: query
          description: Service name
          schema:
            type: string
        - name: metricName
          in: query
          description: Metric name
          required: true
          schema:
            type: string
        - name: aggregation
          in: query
          description: Aggregation function for multi-timeseries results
          schema:
            $ref: '#/components/schemas/AggregationOperator'
        - name: step
          in: query
          description: Mimir query step (resolution) in seconds
          schema:
            minimum: 0
            type: integer
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: Successfully returned metrics data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricQueryResponse'
        '400':
          description: One of the query parameters is invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '401':
          description: Authorization information is missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '500':
          description: Unexpected error occurred
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '504':
          description: Upstream service read timeout occurred
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
  /metrics/prediction:
    get:
      tags:
        - metrics
      summary: Get metric predictions for given parameters
      operationId: getMetricPredictions
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Tenant header
          schema:
            type: string
        - name: startTimestamp
          in: query
          description: From
          required: true
          schema:
            minimum: 0
            type: integer
            format: int64
        - name: endTimestamp
          in: query
          description: To
          required: true
          schema:
            minimum: 0
            type: integer
            format: int64
        - name: namespace
          in: query
          description: Service namespace
          required: true
          schema:
            type: string
        - name: serviceName
          in: query
          description: Service name
          required: true
          schema:
            type: string
        - name: metricName
          in: query
          description: Metric name
          required: true
          schema:
            type: string
        - name: step
          in: query
          description: Mimir query step (resolution) in seconds
          schema:
            minimum: 0
            type: integer
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: Successfully returned metrics data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricQueryResponse'
        '400':
          description: One of the query parameters is invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '401':
          description: Authorization information is missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '500':
          description: Unexpected error occurred
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '504':
          description: Upstream service read timeout occurred
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
  /metrics/resources:
    get:
      tags:
        - resources
      summary: Get current resources usage for a given service
      operationId: getServiceResourceUsageMetrics
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Tenant header
          schema:
            type: string
        - name: serviceName
          in: query
          required: true
          schema:
            type: string
        - name: namespace
          in: query
          required: true
          schema:
            type: string
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: Successfully returned metrics data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ServiceResourceUsageResponse'
        '400':
          description: One of the query parameters is invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '401':
          description: Authorization information is missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '404':
          description: Couldn't find resources for given service
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '500':
          description: Unexpected error occurred
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '504':
          description: Upstream service read timeout occurred
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
  /metrics/traffic:
    get:
      tags:
        - traffic
      summary: Get current traffic for a given service
      operationId: getServiceTrafficMetrics
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Tenant header
          schema:
            type: string
        - name: startTimestamp
          in: query
          description: From
          required: true
          schema:
            minimum: 0
            type: integer
            format: int64
        - name: endTimestamp
          in: query
          description: To
          required: true
          schema:
            minimum: 0
            type: integer
            format: int64
        - name: serviceName
          in: query
          description: Service name
          required: true
          schema:
            type: string
        - name: namespace
          in: query
          description: Namespace
          required: true
          schema:
            type: string
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: Successfully returned metrics data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ServiceResourceUsageResponse'
        '400':
          description: One of the query parameters is invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '401':
          description: Authorization information is missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '404':
          description: Couldn't find resources for given service
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '500':
          description: Unexpected error occurred
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '504':
          description: Upstream service read timeout occurred
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
components:
  schemas:
    AbstractResource_JsonError_:
      type: object
      properties:
        _links:
          type: object
          additionalProperties: true
        _embedded:
          type: object
          additionalProperties:
            type: array
            items:
              $ref: '#/components/schemas/Resource'
    AggregationOperator:
      type: string
      description: Metrics aggregation operators handled by the service.
      enum:
        - MIN
        - MAX
        - AVG
        - SUM
    Charset:
      type: object
      properties:
        registered:
          type: boolean
    JsonError:
      type: object
      allOf:
        - $ref: '#/components/schemas/AbstractResource_JsonError_'
        - required:
            - message
          properties:
            _links:
              type: object
              additionalProperties: true
            _embedded:
              type: object
              additionalProperties:
                type: array
                items:
                  $ref: '#/components/schemas/Resource'
            message:
              type: string
            logref:
              type: string
              nullable: true
            path:
              type: string
              nullable: true
    MediaType:
      required:
        - name
      type: object
      properties:
        name:
          type: string
        type:
          type: string
        subtype:
          type: string
        extension:
          type: string
        parameters:
          $ref: '#/components/schemas/OptionalValues_String_'
        quality:
          type: string
        qualityAsNumber:
          type: number
        version:
          type: string
        charset:
          nullable: true
          allOf:
            - $ref: '#/components/schemas/Charset'
        textBased:
          type: boolean
    MetricEntry:
      required:
        - labels
        - values
      type: object
      properties:
        labels:
          type: object
          additionalProperties:
            type: string
          description: Labels available on particular metrics
        values:
          type: array
          description: Values present on metrics
          items:
            type: object
            additionalProperties:
              type: string
      description: >-
        DTO aggregator for Mimir metrics. It is used by final response object
        MetricQueryResponse
    MetricQueryResponse:
      required:
        - commonLabels
        - metricEntryList
        - step
      type: object
      properties:
        step:
          type: integer
          format: int32
        commonLabels:
          type: object
          additionalProperties:
            type: string
        metricEntryList:
          type: array
          items:
            $ref: '#/components/schemas/MetricEntry'
      description: DTO for Metric query response.
    OptionalMultiValues_Link_:
      $ref: '#/components/schemas/OptionalValues_List_Link__'
    OptionalMultiValues_Resource_:
      $ref: '#/components/schemas/OptionalValues_List_Resource__'
    OptionalValues_List_Link__:
      type: object
      properties:
        empty:
          type: boolean
    OptionalValues_List_Resource__:
      type: object
      properties:
        empty:
          type: boolean
    OptionalValues_String_:
      type: object
      properties:
        empty:
          type: boolean
    Resource:
      type: object
      properties:
        _links:
          $ref: '#/components/schemas/OptionalMultiValues_Link_'
        _embedded:
          $ref: '#/components/schemas/OptionalMultiValues_Resource_'
    ServiceResourceUsageResponse:
      required:
        - pods
      type: object
      properties:
        pods:
          type: array
          items:
            $ref: '#/components/schemas/ServiceResourceUsageResponse.Pod'
      description: A DTO class containing service resources' usage.
    ServiceResourceUsageResponse.Pod:
      required:
        - name
      type: object
      properties:
        name:
          type: string
        resources:
          allOf:
            - type: object
              additionalProperties:
                type: number
                format: double
            - description: The resource's usage in cores for CPU or bytes for memory
