mirror of
https://github.com/kopia/kopia.git
synced 2026-01-23 22:07:54 -05:00
New flag `--enable-jaeger-collector` and the corresponding `KOPIA_ENABLE_JAEGER_COLLECTOR` environment variable enables Jaeger exporter, which by default sends OTEL traces to Jaeger collector on http://localhost:14268/api/traces To change this, use environment variables: * `OTEL_EXPORTER_JAEGER_ENDPOINT` * `OTEL_EXPORTER_JAEGER_USER` * `OTEL_EXPORTER_JAEGER_PASSWORD` When tracing is disabled, the impact on performance is negligible. To see this in action: 1. Download latest Jaeger all-in-one from https://www.jaegertracing.io/download/ 2. Run `jaeger-all-in-one` binary without any parameters. 3. Run `kopia --enable-jaeger-collector snapshot create ...` 4. Go to http://localhost:16686/search and search for traces
80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/kopia/kopia/internal/testutil"
|
|
"github.com/kopia/kopia/tests/testenv"
|
|
)
|
|
|
|
func TestMetricsPushFlags(t *testing.T) {
|
|
env := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
var (
|
|
mu sync.Mutex
|
|
urls []string
|
|
bodies []string
|
|
auths []string
|
|
)
|
|
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
urls = append(urls, r.RequestURI)
|
|
d, _ := io.ReadAll(r.Body)
|
|
bodies = append(bodies, r.Method+":"+string(d))
|
|
u, p, _ := r.BasicAuth()
|
|
|
|
auths = append(auths, u+":"+p)
|
|
})
|
|
|
|
tmp1 := testutil.TempDirectory(t)
|
|
|
|
server := httptest.NewServer(mux)
|
|
defer server.Close()
|
|
|
|
env.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", tmp1,
|
|
"--metrics-push-addr="+server.URL,
|
|
"--metrics-push-interval=30s",
|
|
"--metrics-push-format=text",
|
|
"--enable-jaeger-collector", // this has no observable effects whether Jaeger is running or not
|
|
)
|
|
|
|
env.RunAndExpectSuccess(t, "repo", "status",
|
|
"--metrics-push-addr="+server.URL,
|
|
"--metrics-push-interval=30s",
|
|
"--metrics-push-grouping=a:b",
|
|
"--metrics-push-username=user1",
|
|
"--metrics-push-password=pass1",
|
|
"--metrics-push-format=proto-text",
|
|
)
|
|
|
|
require.Equal(t, []string{
|
|
"/metrics/job/kopia", // initial
|
|
"/metrics/job/kopia", // final
|
|
"/metrics/job/kopia/a/b", // initial
|
|
"/metrics/job/kopia/a/b", // final
|
|
}, urls)
|
|
|
|
require.Equal(t, "user1:pass1", auths[len(auths)-1])
|
|
|
|
for _, b := range bodies {
|
|
// make sure bodies include some kopia metrics, don't need more
|
|
require.Contains(t, b, "kopia_content_cache_hit_bytes")
|
|
}
|
|
|
|
env.RunAndExpectFailure(t, "repo", "status",
|
|
"--metrics-push-addr="+server.URL,
|
|
"--metrics-push-grouping=a=s",
|
|
)
|
|
}
|