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

fix: move object store read/write timer into inner #3627

Merged

Conversation

dimbtp
Copy link
Contributor

@dimbtp dimbtp commented Apr 1, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#3622

What's changed and what's your intention?

Move timer from read/write function into PrometheusMetricWrapper and update data when dropping to get accurate metric.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR does not require documentation updates.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Apr 1, 2024
@dimbtp
Copy link
Contributor Author

dimbtp commented Apr 1, 2024

Question:
In #3622, the inner method returns a writer which indicates that the actual write operation does not perform yet, but I don't find write function try to return a writer. It seems all the write jobs are awaited.

@evenyag
Copy link
Contributor

evenyag commented Apr 2, 2024

Question: In #3622, the inner method returns a writer which indicates that the actual write operation does not perform yet, but I don't find write function try to return a writer. It seems all the write jobs are awaited.

The return value of that async method is (RpWrite, Self::Writer). So we only get a writer after await.

async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {

The operator writes to the writer later.
https://github.com/apache/opendal/blob/50791255c6ef3ed259c88dcc04a4295fa60fa443/core/src/types/operator/operator.rs#L1246-L1250

You could refer to the metrics layer in opendal v0.45.1
https://github.com/apache/opendal/blob/v0.45.1/core/src/layers/metrics.rs#L744-L752
https://github.com/apache/opendal/blob/v0.45.1/core/src/layers/metrics.rs#L765-L773

It observes the timer in drop()

impl<R> Drop for MetricWrapper<R> {
    fn drop(&mut self) {
        self.bytes_counter.increment(self.bytes);
        if let Some(instant) = self.start {
            let dur = instant.elapsed().as_secs_f64();
            self.requests_duration_seconds.record(dur);
        }
    }
}

This behavior changes in the main branch after apache/opendal#4381 but v0.45.1 is still the latest release we are using so we should follow its implementation. I have updated links in #3622

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 65.51724% with 30 lines in your changes are missing coverage. Please review.

Project coverage is 84.81%. Comparing base (6c316d2) to head (1372e5d).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3627      +/-   ##
==========================================
- Coverage   85.36%   84.81%   -0.55%     
==========================================
  Files         935      943       +8     
  Lines      156348   156962     +614     
==========================================
- Hits       133463   133128     -335     
- Misses      22885    23834     +949     

@dimbtp
Copy link
Contributor Author

dimbtp commented Apr 2, 2024

@evenyag Thanks for your information. Please take a took.

Copy link
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

We should move the histogram timer to the PrometheusMetricWrapper. The timer will track the start time and duration for us.

src/object-store/src/layers/prometheus.rs Outdated Show resolved Hide resolved
src/object-store/src/layers/prometheus.rs Outdated Show resolved Hide resolved
src/object-store/src/layers/prometheus.rs Outdated Show resolved Hide resolved
src/object-store/src/layers/prometheus.rs Outdated Show resolved Hide resolved
src/object-store/src/layers/prometheus.rs Outdated Show resolved Hide resolved
src/object-store/src/layers/prometheus.rs Outdated Show resolved Hide resolved
@dimbtp
Copy link
Contributor Author

dimbtp commented Apr 2, 2024

@evenyag I leave some messages, please take a look.

@dimbtp dimbtp requested a review from evenyag April 3, 2024 05:52
Copy link
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

We can get rid of Option in this way.

src/object-store/src/layers/prometheus.rs Outdated Show resolved Hide resolved
src/object-store/src/layers/prometheus.rs Outdated Show resolved Hide resolved
@dimbtp dimbtp requested a review from evenyag April 3, 2024 06:49
Copy link
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

LGTM

@killme2008 killme2008 added this pull request to the merge queue Apr 3, 2024
Merged via the queue into GreptimeTeam:main with commit 86d377d Apr 3, 2024
18 checks passed
@dimbtp dimbtp deleted the fix/inaccurate-object-store-metric branch April 3, 2024 15:16
MichaelScofield pushed a commit to MichaelScofield/greptimedb that referenced this pull request Apr 7, 2024
* fix: move object store read/write timer into inner

* add Drop for PrometheusMetricWrapper

* call await on async read/write

* apply review comments

* git rid of option on timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants