census-instrumentation / opencensus-go

A stats collection and distributed tracing framework
http://opencensus.io
Apache License 2.0
2.05k stars 327 forks source link

[ochttp] KeyClientHost tag doesn't change in exported Prometheus metrics #1263

Open mzanibelli opened 3 years ago

mzanibelli commented 3 years ago

More of a question than a bug.

What version of OpenCensus are you using?

v0.23.0

What version of Go are you using?

1.17

What did you do?

Register a client view like this:

{
    Name:        "httpclient_latency",
    TagKeys:     []tag.Key{ochttp.KeyClientHost, ochttp.KeyClientStatus},
    Measure:     ochttp.ClientRoundtripLatency,
    Aggregation: ochttp.DefaultLatencyDistribution,
}

Then use the ochttp plugin via the Prometheus exporter: make queries to different hosts returning different status codes.

What did you expect to see?

Prometheus metrics with varying labels according to Host and Status Code.

httpclient_latency_bucket{http_client_host="host1",http_client_status="500",le="1"} 2
httpclient_latency_bucket{http_client_host="host1",http_client_status="200",le="1"} 2
httpclient_latency_bucket{http_client_host="host2",http_client_status="500",le="1"} 2
httpclient_latency_bucket{http_client_host="host2",http_client_status="200",le="1"} 2
// ...

Note that I have different rows according to hosts.

What did you see instead?

Only the status code variation results in different rows. The host label keeps the value of the first request's host header.

httpclient_latency_bucket{http_client_host="host1",http_client_status="500",le="1"} 4
httpclient_latency_bucket{http_client_host="host1",http_client_status="200",le="1"} 4
// ...

Additional context

This is maybe the intended behavior.

I started using OpenCensus (with KrakenD API gateway) not so long ago and I tried looking up current issues/PRs/specs to no avail.

Looking at the ochttp code, I see that client stats seem to be only recorded with status code tags for these particular measurements. https://github.com/census-instrumentation/opencensus-go/blob/49838f207d61097fc0ebb8aeef306913388376ca/plugin/ochttp/client_stats.go#L118-L121

I have a hard time understanding the reason behind such a behavior: is it just not implemented yet? Is it to avoid high cardinality? Am I misusing something here?

Would it be possible/a good idea to pass the host to the tracker struct in order to perform stats.RecordWithTags with more tags?

Thanks in advance for your help.