census-instrumentation/opencensus-go

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

mzanibelli opened this issue · 0 comments

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.

stats.RecordWithTags(t.ctx, []tag.Mutator{
tag.Upsert(StatusCode, strconv.Itoa(t.statusCode)),
tag.Upsert(KeyClientStatus, strconv.Itoa(t.statusCode)),
}, m...)

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.