# Copyright 2024 RustFS Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: 1

datasources:
  - name: Prometheus
    type: prometheus
    uid: prometheus
    access: proxy
    orgId: 1
    url: http://prometheus:9090
    isDefault: true
    version: 1
    editable: false
    jsonData:
      httpMethod: GET
      exemplarTraceIdDestinations:
        - name: trace_id
          datasourceUid: tempo

  - name: Tempo
    type: tempo
    uid: tempo
    access: proxy
    orgId: 1
    url: http://tempo:3200
    isDefault: false
    version: 1
    editable: false
    jsonData:
      httpMethod: GET
      serviceMap:
        datasourceUid: prometheus
      tracesToLogs:
        datasourceUid: loki
        tags: [ 'job', 'instance', 'pod', 'namespace', 'service.name' ]
        mappedTags: [ { key: 'service.name', value: 'app' } ]
        spanStartTimeShift: '1s'
        spanEndTimeShift: '-1s'
        filterByTraceID: true
        filterBySpanID: false
      tracesToMetrics:
        datasourceUid: prometheus
        tags: [ { key: 'service.name' }, { key: 'job' } ]
        queries:
          - name: 'Service-Level Latency'
            query: 'sum(rate(traces_spanmetrics_latency_bucket{$$__tags}[5m])) by (le)'
          - name: 'Service-Level Calls'
            query: 'sum(rate(traces_spanmetrics_calls_total{$$__tags}[5m]))'
          - name: 'Service-Level Errors'
            query: 'sum(rate(traces_spanmetrics_calls_total{status_code="ERROR", $$__tags}[5m]))'
      nodeGraph:
        enabled: true

  - name: Loki
    type: loki
    uid: loki
    orgId: 1
    url: http://loki:3100
    isDefault: false
    version: 1
    editable: false
    jsonData:
      derivedFields:
        - datasourceUid: tempo
          matcherRegex: 'trace_id=(\w+)'
          name: 'TraceID'
          url: '$${__value.raw}'

  - name: Jaeger
    type: jaeger
    uid: jaeger
    url: http://jaeger:16686
    access: proxy
    isDefault: false
    editable: false
    jsonData:
      tracesToLogs:
        datasourceUid: loki
        tags: [ 'job', 'instance', 'pod', 'namespace', 'service.name' ]
        mappedTags: [ { key: 'service.name', value: 'app' } ]
        spanStartTimeShift: '1s'
        spanEndTimeShift: '-1s'
        filterByTraceID: true
        filterBySpanID: false
