Observability

Максим Иванов

Что такое observability

Насколько по наблюдаемым сигналам можно понять внутреннее состояние системы:

2

Три "столпа"

3

Практические сигналы

4

Prometheus architecture

5

Prometheus Data Model

http_requests_total
<metric name>{<label name>=<label value>, ...}
api_http_requests_total{method="POST", handler="/messages"}
6

Prometheus query language

7

Prometheus client: expose /metrics

package main

import (
        "net/http"

        "github.com/prometheus/client_golang/prometheus/promhttp"
)

func main() {
        http.Handle("/metrics", promhttp.Handler())
        http.ListenAndServe(":2112", nil)
}
8

Prometheus client: Counter

func recordMetrics() {
    go func() {
        for {
            opsProcessed.Inc()
            time.Sleep(2 * time.Second)
        }
    }()
}

var (
    opsProcessed = promauto.NewCounter(prometheus.CounterOpts{
        Name: "myapp_processed_ops_total",
        Help: "The total number of processed events",
    })
)
9

Prometheus client: CounterVec

var (
    reg = prometheus.NewRegistry()
    requestCount = promauto.With(reg).NewCounterVec(
        prometheus.CounterOpts{
            Name: "http_requests_total",
            Help: "Total number of HTTP requests by status code and method.",
        },
        []string{"code", "method"},
    )
)

func countRequest(code, method string) {
    requestCount.WithLabelValues(code, method).Inc()
}
10

Example: Request Handlers

Что измерять?

11

Example: Request Handlers

12

Example: Job Queue

Что измерять?

13

Example: Job Queue

14

Example: Database Pool

Что измерять?

15

Example: Database Pool

16

OpenTelemetry data model

17

Jaeger architecture

18

Как OTel и Jaeger связываются

19

Trace API examples

var (
    tracer = otel.Tracer("rolldice")
)

func rolldice(w http.ResponseWriter, r *http.Request) {
    ctx, span := tracer.Start(r.Context(), "roll")
    defer span.End()

    roll := 1 + rand.Intn(6)

    span.SetAttributes(attribute.Int("roll.value", roll))

    resp := strconv.Itoa(roll) + "\n"
    if _, err := io.WriteString(w, resp); err != nil {
        span.RecordError(err)
    }
}
20

HTTP Propagation

> GET / HTTP/1.1
> Host: localhost:3001
> Accept: */*
> traceparent: 00-d4cda95b652f4a1592b449d5929fda1b-6e0c63257de34c92-01
21

Thank you

Максим Иванов

Use the left and right arrow keys or click the left and right edges of the page to navigate between slides.
(Press 'H' or navigate to hide this message.)