mirror of
https://github.com/kopia/kopia.git
synced 2026-01-25 14:58:00 -05:00
This may be a breaking change for users who rely on particular kopia metrics (unlikely):
- introduced blob-level metrics:
* `kopia_blob_download_full_blob_bytes_total`
* `kopia_blob_download_partial_blob_bytes_total`
* `kopia_blob_upload_bytes_total`
* `kopia_blob_storage_latency_ms` - per-method latency distribution
* `kopia_blob_errors_total` - per-method error counter
- updated cache metrics to indicate particular cache
* `kopia_cache_hit_bytes_total{cache="CACHE_TYPE"}`
* `kopia_cache_hit_total{cache="CACHE_TYPE"}`
* `kopia_cache_malformed_total{cache="CACHE_TYPE"}`
* `kopia_cache_miss_total{cache="CACHE_TYPE"}`
* `kopia_cache_miss_errors_total{cache="CACHE_TYPE"}`
* `kopia_cache_miss_bytes_total{cache="CACHE_TYPE"}`
* `kopia_cache_store_errors_total{cache="CACHE_TYPE"}`
where `CACHE_TYPE` is one of `contents`, `metadata` or `index-blobs`
- reorganized and unified content-level metrics:
* `kopia_content_write_bytes_total`
* `kopia_content_write_duration_nanos_total`
* `kopia_content_compression_attempted_bytes_total`
* `kopia_content_compression_attempted_duration_nanos_total`
* `kopia_content_compression_savings_bytes_total`
* `kopia_content_compressible_bytes_total`
* `kopia_content_non_compressible_bytes_total`
* `kopia_content_after_compression_bytes_total`
* `kopia_content_decompressed_bytes_total`
* `kopia_content_decompressed_duration_nanos_total`
* `kopia_content_encrypted_bytes_total`
* `kopia_content_encrypted_duration_nanos_total`
* `kopia_content_hashed_bytes_total`
* `kopia_content_hashed_duration_nanos_total`
* `kopia_content_deduplicated_bytes_total`
* `kopia_content_read_bytes_total`
* `kopia_content_read_duration_nanos_total`
* `kopia_content_decrypted_bytes_total`
* `kopia_content_decrypted_duration_nanos_total`
* `kopia_content_uploaded_bytes_total`
Also introduced `internal/metrics` framework which constructs Prometheus metrics in a uniform way and will allow us to include some of these metrics in telemetry report in future PRs.
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_cache_hit_bytes_total")
|
|
}
|
|
|
|
env.RunAndExpectFailure(t, "repo", "status",
|
|
"--metrics-push-addr="+server.URL,
|
|
"--metrics-push-grouping=a=s",
|
|
)
|
|
}
|