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

Add a new metric for OpenSearch Sink plugin: bulkRequestSizeBytes #572

Merged
merged 2 commits into from
Nov 16, 2021

Conversation

jianghancn
Copy link
Contributor

@jianghancn jianghancn commented Nov 12, 2021

Signed-off-by: Han Jiang [email protected]

Description

Having the OpenSearch Sink emit a metric, bulkRequestSizeBytes, right before the request sending the batch to OpenSearch.

Issues Resolved

#571

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@codecov-commenter
Copy link

Codecov Report

Merging #572 (a456b14) into main (52e0468) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##               main     #572   +/-   ##
=========================================
  Coverage     92.28%   92.28%           
  Complexity      569      569           
=========================================
  Files            71       71           
  Lines          1725     1725           
  Branches        144      144           
=========================================
  Hits           1592     1592           
  Misses          102      102           
  Partials         31       31           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52e0468...a456b14. Read the comment docs.

public OpenSearchSink(final PluginSetting pluginSetting) {
super(pluginSetting);
bulkRequestTimer = pluginMetrics.timer(BULKREQUEST_LATENCY);
bulkRequestErrorsCounter = pluginMetrics.counter(BULKREQUEST_ERRORS);
bulkRequestSizeBytes = pluginMetrics.gauge(BULKREQUEST_SIZE_BYTES, new AtomicLong());
Copy link
Member

@graytaylor0 graytaylor0 Nov 12, 2021

Choose a reason for hiding this comment

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

Is there a reason you use a guage here? It appears that you are only incrementing. If that is the case you should use a Counter

Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend using a summary metric here. This is the metric type we have used in the HttpSource to measure payload size of the requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a reason you use a guage here? It appears that you are only incrementing. If that is the case you should use a Counter

I would recommend using a summary metric here. This is the metric type we have used in the HttpSource to measure payload size of the requests.

My understanding is counters simply add metrics together. It's hard to tell the different sizes for different bulks. Thus, I was finding a different mechanism. Now Chris' summary metric type seems to be the best. It help tell the sizes of individual bulks.

I have published the new revision using summary

@@ -165,6 +170,7 @@ private void flushBatch(final BulkRequest bulkRequest) {
bulkRequestTimer.record(() -> {
try {
bulkRetryStrategy.execute(bulkRequest);
bulkRequestSizeBytes.addAndGet(bulkRequest.estimatedSizeInBytes());
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why an AtomicLong is required here? Why wouldn't it be thread safe to just increment a Counter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw all other places using gauge also uses AtomicLong, and it seems to be safer since we do have many threads. Now we are using Summary, we don't have this concern any longer.

Copy link
Contributor

@cmanning09 cmanning09 left a comment

Choose a reason for hiding this comment

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

Thanks Han, In addition to the other comments. Please update the README for this plugin with this new metric.

public OpenSearchSink(final PluginSetting pluginSetting) {
super(pluginSetting);
bulkRequestTimer = pluginMetrics.timer(BULKREQUEST_LATENCY);
bulkRequestErrorsCounter = pluginMetrics.counter(BULKREQUEST_ERRORS);
bulkRequestSizeBytes = pluginMetrics.gauge(BULKREQUEST_SIZE_BYTES, new AtomicLong());
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend using a summary metric here. This is the metric type we have used in the HttpSource to measure payload size of the requests.

@jianghancn jianghancn requested a review from a team as a code owner November 15, 2021 21:53
@jianghancn
Copy link
Contributor Author

Thanks Han, In addition to the other comments. Please update the README for this plugin with this new metric.

Updated README. Thanks.

@jianghancn jianghancn merged commit 54f8ce7 into opensearch-project:main Nov 16, 2021
dapowers87 pushed a commit to dapowers87/data-prepper that referenced this pull request Nov 18, 2021
…ensearch-project#572)

* Add a new metric for OpenSearch Sink plugin: bulkRequestSizeBytes
Signed-off-by: Han Jiang <[email protected]>

* Using summary as the instrumenting mechanism for collecting bulkRequestSizeBytes metrics
Signed-off-by: Han Jiang <[email protected]>
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