Skip to content

feat(processors.cumulative_sum): Add plugin #16629

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

Merged

Conversation

opengamer29
Copy link
Contributor

Summary

We collect metrics from a large amount of mobile devices and scrape aggregated data with Prometheus. We don't have a monotonic increasing without cumulative effect (like for histogram aggregator). Sum is reset based on period settings, which prevents us from building graphs with different time intervals.

This MR add a new config property to allow accumulate data for a long period of time even between resets.

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #16591

@telegraf-tiger telegraf-tiger bot added feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/aggregator 1. Request for new aggregator plugins 2. Issues/PRs that are related to aggregator plugins labels Mar 13, 2025
@opengamer29 opengamer29 force-pushed the feat/basic_status_cumulative_interval branch from 34fb9ff to 06d9196 Compare March 13, 2025 16:52
@srebhan
Copy link
Member

srebhan commented Mar 21, 2025

@opengamer29 thanks for your contribution! However, I don't think this is the right thing to do here. How about creating a new processor that accumulates (cumulative sums) the values per metric-series and output the summed value for each field? This is closer to what you want and you get the absolute sample points (at least relative to Telegraf's start) in the highest frequency you want... You afterwards can still aggregate the metrics...

@srebhan srebhan self-assigned this Mar 21, 2025
@opengamer29
Copy link
Contributor Author

@srebhan It definitely makes sense. Thank you for your feedback. I'll change this MR following your recommendation this or next week.

@opengamer29 opengamer29 force-pushed the feat/basic_status_cumulative_interval branch 4 times, most recently from f5e4d08 to 497956f Compare April 7, 2025 10:47
@opengamer29
Copy link
Contributor Author

I'm not sure what should I do with that Lint plugin readmes / run-readme-linter check. It's something new and other processor plugins don't have it. It will be great to add some recommendations to contributing documentations.

@srebhan srebhan changed the title feat(aggregators.basicstats): Add cumulative interval (#16591) feat(processors.cumulative_sum): Add plugin Apr 9, 2025
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks for the rework @opengamer29! Some comments in the code...

@srebhan
Copy link
Member

srebhan commented Apr 9, 2025

@opengamer29 ignore the linter issues for now, we are working on it.

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks for the update @opengamer29! Please find my comments below. Let's first get the plugin code right and then look at the tests afterwards...

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Some more suggestions @opengamer29...

@srebhan
Copy link
Member

srebhan commented Apr 23, 2025

@opengamer29 any chance you address the comments in the near future? We would really love to ship this plugin with v1.35.0...

@srebhan srebhan added the waiting for response waiting for response from contributor label Apr 23, 2025
@opengamer29
Copy link
Contributor Author

@opengamer29 any chance you address the comments in the near future? We would really love to ship this plugin with v1.35.0...

I'm on vacation right now, but I will look through all the comments next week. Do you think it will work for you?

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label Apr 23, 2025
@opengamer29
Copy link
Contributor Author

@srebhan I’m keeping in mind my use case with Prometheus output, where I only need the cumulative sum, without retaining the original metrics. Based on your experience, do you foresee broader use cases for this processor plugin?

Would it make sense to split the functionality into two separate plugins:
– a processor that appends cumulative sums to existing metrics,
– an aggregator that outputs only the cumulative sum (similar to the initial commits)?

The cumulative sum aggregator would be a perfect fit for my case — minimal memory overhead, no need for additional deduplication, and a single pass through the metrics array.

The processor-based approach does look more flexible and may be useful in other use cases. However, for my use case, it’s not optimal in terms of memory usage and performance. I feel it might be more efficient and transparent to continue using a Starlark-based aggregator on my end.

@Hipska
Copy link
Contributor

Hipska commented Apr 25, 2025

You could keep this as a processor, but then use for example aggregators.final to emit only 1 (the last) metric in your desired interval.

See the docs on the difference between processors and aggregators.

@opengamer29 opengamer29 force-pushed the feat/basic_status_cumulative_interval branch from 46b2c34 to d39537e Compare April 25, 2025 11:39
@opengamer29
Copy link
Contributor Author

You could keep this as a processor, but then use for example aggregators.final to emit only 1 (the last) metric in your desired interval.

See the docs on the difference between processors and aggregators.

Yes, using a processor combined with aggregators.final is technically possible, but it still introduces some overhead. If this plugin ends up being used primarily in scenarios like mine, where only the final cumulative value is needed, it will always be paired with the aggregators.final or similar. Do you see this as an expected usage?

That's why I asked about the cumulative aggregator plugin.

Copy link
Contributor

@Hipska Hipska left a comment

Choose a reason for hiding this comment

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

Great, looks almost good!

@opengamer29 opengamer29 force-pushed the feat/basic_status_cumulative_interval branch from 531ff8e to cae565c Compare April 25, 2025 14:44
@srebhan
Copy link
Member

srebhan commented Apr 28, 2025

@opengamer29 sorry for the late reply, I'm travelling currently... Yes I do imagine a broader use of this plugin as e.g. some energy meters can only report the change between two gather cycles. So having a generic operation like the cumulative sum makes a lot of sense.

This being said, we have to make sure that the operation is generic but also covers your use case. Moreover, we have to keep in mind the other plugins we have and not double functionality we already provide as this would create a maintenance nightmare over time.

This being said, a drop_original_fields flag is doing just the same as the general fieldexclude. Hard resetting the metrics also hardly makes sense. However, you use case of expiring metrics does make sense. So my suggestion is to keep the expiry flag(s) but name it as such. You also could add an option for setting the "sum-field-suffix" with an empty suffix meaning override the original fields.
Regarding the processor vs aggregator discussion I fully second @Hipska! We should keep this as a processor because it makes sense! An aggregator always introduces additional delays in the data processing. For some operations that's the only way but it is unnecessary for a cumulative sum.

Does that help?

@opengamer29
Copy link
Contributor Author

@opengamer29 could you please run make fmt on the PR!? This should fix the linter issues. Besides from the linter issues we are good to go...

make fmt doesn't make any changes even after rebase to main branch. I also tried run gofmt -w manually, still nothing...
What do I miss?

@opengamer29 opengamer29 force-pushed the feat/basic_status_cumulative_interval branch from 09801d5 to a6cf696 Compare May 8, 2025 14:06
@Hipska
Copy link
Contributor

Hipska commented May 8, 2025

You could check the actual output of the checks:

  /github/workspace/plugins/processors/cumulative_sum/README.md:3:80 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
  /github/workspace/plugins/processors/cumulative_sum/README.md:4:80 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
  /github/workspace/plugins/processors/cumulative_sum/README.md:8:81 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
plugins/processors/cumulative_sum/README.md:1: metadata is missing
plugins/processors/cumulative_sum/cumulative_sum_test.go:4:1  gci  File is not properly formatted
1 issues:
* gci: 1

@opengamer29
Copy link
Contributor Author

opengamer29 commented May 8, 2025

You could check the actual output of the checks:

@Hipska Thank you for provided output. I don't have any output after make fmt command. I don't know why :(

And what should you do with metadata is missing. Following rules.go it's something new in project and none of processors have it. Should I add something like?

⭐ Telegraf v1.35.0
🏷️ statistics
💻 all

@Hipska
Copy link
Contributor

Hipska commented May 8, 2025

The output came from the failing checks here on GitHub.

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the linter issues @opengamer29! Ignore the missing metadata for now, I will add this as it is also missing for all other processors still...

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label May 12, 2025
@srebhan srebhan assigned skartikey and mstrandboge and unassigned srebhan May 12, 2025
@telegraf-tiger
Copy link
Contributor

Copy link
Contributor

@skartikey skartikey left a comment

Choose a reason for hiding this comment

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

@opengamer29 Thanks for your contribution!

@skartikey skartikey merged commit 5f63d4b into influxdata:master May 13, 2025
26 of 27 checks passed
@github-actions github-actions bot added this to the v1.35.0 milestone May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/aggregator 1. Request for new aggregator plugins 2. Issues/PRs that are related to aggregator plugins plugin/processor ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Basic stats aggregator plugin's cumulative effect for Prometheus scraping
5 participants