Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

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

Open
mzanibelli opened this issue Aug 27, 2021 · 0 comments
Open
Labels

Comments

@mzanibelli
Copy link

mzanibelli commented Aug 27, 2021

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.

@mzanibelli mzanibelli added the bug label Aug 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant