# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: ⚠️ Tempo
spec:
    description: An open-source, easy-to-use, and high-scale distributed tracing backend
    coverImage: https://cdn.zeabur.com/templates/cover-image/grafana-tempo.png
    icon: https://cdn.zeabur.com/templates/icon/grafana-tempo.svg
    variables:
        - key: RUSTFS_CONSOLE_DOMAIN
          type: DOMAIN
          name: RustFS Console Domain
          description: The domain of the RustFS console
    tags:
        - monitoring
        - observability
        - tracing
    readme: |
        Grafana Tempo is an open-source, easy-to-use, and high-scale distributed tracing backend. Tempo lets you search for traces, generate metrics from spans, and link your tracing data with logs and metrics.

        You usually compose it with [Grafana](https://zeabur.com/templates/MDTTQR).

        ## Usage

        After deployment, you should create a bucket on RustFS Console and set the bucket name to `tempo`. Then, you can restart the Tempo service to use the S3 bucket.

        We have exposed Jaeger HTTP API (port `14268`), OpenTelemetry HTTP API (port `4318`), and OpenTelemetry gRPC API (port `4317`) for tracing; Tempo HTTP API for querying traces (port `3200`). You should get the port mapping from the “Networking” tab in the “Services” section.

        For other methods or configuration, you should enable them in the `tempo.yaml` file on [Config Editor](https://zeabur.com/docs/data-management/config-edit).
    services:
        - name: tempo-memcached
          icon: https://cdn.zeabur.com/prebuilt.svg
          template: PREBUILT
          spec:
            source:
                image: memcached:1.6
                runAsUserID: 11211
            ports:
                - id: memcached
                  port: 11211
                  type: TCP
        - name: tempo-s3
          icon: https://cdn.zeabur.com/templates/icon/rustfs-logo-square.png
          template: PREBUILT
          spec:
            source:
                image: rustfs/rustfs:latest
            ports:
                - id: web
                  port: 9000
                  type: HTTP
                - id: console
                  port: 9001
                  type: HTTP
            volumes:
                - id: data
                  dir: /data
            instructions:
                - title: Default Username (S3 Access Key ID)
                  content: ${RUSTFS_USERNAME}
                - title: Default Password (S3 Secret Access Key)
                  content: ${RUSTFS_PASSWORD}
            env:
                RUSTFS_ACCESS_KEY:
                    default: rustfs
                RUSTFS_PASSWORD:
                    default: ${RUSTFS_SECRET_KEY}
                RUSTFS_SECRET_KEY:
                    default: ${PASSWORD}
                RUSTFS_USERNAME:
                    default: ${RUSTFS_ACCESS_KEY}
                TEMPO_S3_ACCESS_KEY:
                    default: ${RUSTFS_ACCESS_KEY}
                    expose: true
                TEMPO_S3_SECRET_KEY:
                    default: ${RUSTFS_SECRET_KEY}
                    expose: true
          domainKey:
            - port: console
              variable: RUSTFS_CONSOLE_DOMAIN
        - name: tempo
          icon: https://cdn.zeabur.com/templates/icon/grafana-tempo.svg
          dependencies:
            - tempo-memcached
            - tempo-s3
          template: PREBUILT
          spec:
            source:
                image: grafana/tempo:latest
                args:
                    - -config.file=/etc/tempo.yaml
            ports:
                - id: jaeger
                  port: 14268
                  type: HTTP
                - id: tempo
                  port: 3200
                  type: HTTP
                - id: otlpgrpc
                  port: 4317
                  type: HTTP
                - id: otlphttp
                  port: 4318
                  type: HTTP
            volumes:
                - id: data
                  dir: /var/tempo
            configs:
                - path: /etc/tempo.yaml
                  template: |
                    stream_over_http_enabled: true
                    server:
                      http_listen_port: 3200
                      log_level: info

                    cache:
                      background:
                        writeback_goroutines: 5
                      caches:
                        - roles:
                            - frontend-search
                          memcached:
                            addresses: dns+tempo-memcached.zeabur.internal:11211

                    query_frontend:
                      mcp_server:
                        enabled: true
                      search:
                        duration_slo: 5s
                        throughput_bytes_slo: 1.073741824e+09
                        metadata_slo:
                          duration_slo: 5s
                          throughput_bytes_slo: 1.073741824e+09
                      trace_by_id:
                        duration_slo: 100ms
                      metrics:
                        query_backend_after: 5m
                        duration_slo: 5s
                        throughput_bytes_slo: 1.073741824e+09

                    distributor:
                      usage:
                        cost_attribution:
                          enabled: true
                      receivers: # this configuration will listen on all ports and protocols that tempo is capable of.
                        jaeger: # the receives all come from the OpenTelemetry collector.  more configuration information can
                          protocols: # be found there: https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver
                            thrift_http: #
                              endpoint: "0.0.0.0:14268" # for a production deployment you should only enable the receivers you need!
                            # grpc:
                            #   endpoint: "0.0.0.0:14250"
                            # thrift_binary:
                            #   endpoint: "0.0.0.0:6832"
                            # thrift_compact:
                            #   endpoint: "0.0.0.0:6831"
                        # zipkin:
                        #   endpoint: "0.0.0.0:9411"
                        otlp:
                          protocols:
                            grpc:
                              endpoint: "0.0.0.0:4317"
                            http:
                              endpoint: "0.0.0.0:4318"
                        # opencensus:
                        #   endpoint: "0.0.0.0:55678"

                    compactor:
                      compaction:
                        block_retention: 168h # overall Tempo trace retention, 168h = 7d

                    storage:
                      trace:
                        backend: s3 # backend configuration to use
                        wal:
                          path: /var/tempo/wal # where to store the wal locally
                        s3:
                          bucket: tempo
                          endpoint: tempo-s3.zeabur.internal:9000
                          access_key: ${TEMPO_S3_ACCESS_KEY}
                          secret_key: ${TEMPO_S3_SECRET_KEY}
                          insecure: true
                  permission: null
                  envsubst: true
