Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds _doc_count for spans and transactions #109

Closed
wants to merge 1 commit into from

Conversation

dgieselaar
Copy link
Member

We've recently had a few requests for upscaling spans and transactions, either when falling back to sampled events in the UI, or for custom dashboards. Currently, throughput drops, which makes it hard to use custom dashboards. Latency and failure results can be skewed. If we set _doc_count to the value of representative_count, Elasticsearch aggregations will automatically upscale results. This PR makes that change. Not sure if this is the way to do it, but it wasn't much work, so gave it a shot anyway.

See:

@dgieselaar dgieselaar requested a review from a team as a code owner July 10, 2023 11:06
@@ -81,12 +83,19 @@ func (e *APMEvent) MarshalFastJSON(w *fastjson.Writer) error {
if e.Transaction != nil {
e.Transaction.toModelJSON(&transaction, e.Processor != nil && e.Processor.Name == "metric" && e.Processor.Event == "metric")
doc.Transaction = &transaction

if e.Transaction.GetRepresentativeCount() >= 1 {
doc.DocCount = int64(math.Round(e.Transaction.GetRepresentativeCount()))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elastic/apm-server perhaps we can distribute the rounding? e.g. if representative count is 1.2, there's a 80% chance it will be rounded down to 1, and 20% it will be rounded up to 2. Or is that a dumb idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep it simple to start with, and round. Hopefully we get a more explicit means of weighting statistics by a floating point field in the future.

Copy link
Contributor

@marclop marclop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good! I'd like @axw to also rubber stamp this since I haven't been too involved in this.

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do this in the ingest pipeline instead? https://github.com/elastic/apm-server/blob/main/apmpackage/apm/data_stream/traces/elasticsearch/ingest_pipeline/default.yml

That way old data will get the field too. Also it will reduce the wire size slightly.

I guess we don't have a better option at the moment, but the use of _doc_count has always been too magical for my liking. I think ideally Elasticsearch would provide a way to explicitly weight aggregations by another field. You can already do weighed averages -- why not for other metrics aggs too?

@dgieselaar
Copy link
Member Author

@axw pipeline sounds fine to me, I'll close this one and move it there. Before I open it, do you have any opinion on distributing the rounding as described in #109 (comment)?

That way old data will get the field too. Also it will reduce the wire size slightly.

What do you mean with "old data"? Older APM Server versions sending data to a more recent cluster (with the most recent package installed)?

I guess we don't have a better option at the moment, but the use of _doc_count has always been too magical for my liking. I think ideally Elasticsearch would provide a way to explicitly weight aggregations by another field. You can already do weighed averages -- why not for other metrics aggs too?

Agreed, and AFAIK _doc_count will be removed eventually. Until then this is a cheap option for us with lots of upsides I think.

@axw
Copy link
Member

axw commented Jul 12, 2023

What do you mean with "old data"? Older APM Server versions sending data to a more recent cluster (with the most recent package installed)?

Exactly

Agreed, and AFAIK _doc_count will be removed eventually. Until then this is a cheap option for us with lots of upsides I think.

🥳

@dgieselaar
Copy link
Member Author

Closing in favor of elastic/apm-server#11217

@dgieselaar dgieselaar closed this Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants