You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "flaneur2020 (via GitHub)" <gi...@apache.org> on 2024/07/17 09:23:04 UTC

[PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

flaneur2020 opened a new pull request, #4907:
URL: https://github.com/apache/opendal/pull/4907

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
   
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking-changes` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1682078470


##########
core/src/layers/prometheus_client.rs:
##########
@@ -159,32 +162,78 @@ impl PrometheusClientMetrics {
             bytes_total,
         }
     }
+}
+
+#[derive(Clone, Debug)]
+struct PrometheusClientMetrics {
+    metrics: Arc<PrometheusClientMetricDefinitions>,
+    scheme: Scheme,
+    root: String,
+    name: String,
+}
+
+impl PrometheusClientMetrics {
+    fn new(
+        metrics: Arc<PrometheusClientMetricDefinitions>,
+        scheme: Scheme,
+        root: String,
+        name: String,
+    ) -> Self {
+        Self {
+            metrics,
+            scheme,
+            root,
+            name,
+        }
+    }
 
-    fn increment_errors_total(&self, scheme: Scheme, op: &'static str, err: ErrorKind) {
+    fn increment_errors_total(&self, op: &'static str, err: ErrorKind) {

Review Comment:
   i switched to a `Cow<'static, str>` in https://github.com/apache/opendal/pull/4907/commits/daab9db22bb84e25f959a44bb0813c44ae32a504 which helps reduces copy but can not reduce all the copies.
   
   it turns out that we can not simply add lifetime annotations (for the labels like `root` and `namespace` which stored in a singleton struct) in the labels type with promtheus-client, because each metric (with labels together) will be registered into a global registry, which requires the metrics to be `'static`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on PR #4907:
URL: https://github.com/apache/opendal/pull/4907#issuecomment-2233046735

   > > does this `root` parameter contain the bucket in it?
   > 
   > No. root is the base path for all opendal operations. You might want to include `name` in the metrics.
   
   thank you for the suggestion, i've added a `namespace` label (i feel afraid that `name` might has some risks conflicting with some built-in prometheus labels) in the appended commit. the `root` label might still be useful for some other cases, i did not remove it after `namespace` added.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1682090099


##########
core/src/layers/prometheus_client.rs:
##########
@@ -159,32 +162,78 @@ impl PrometheusClientMetrics {
             bytes_total,
         }
     }
+}
+
+#[derive(Clone, Debug)]
+struct PrometheusClientMetrics {
+    metrics: Arc<PrometheusClientMetricDefinitions>,
+    scheme: Scheme,
+    root: String,
+    name: String,
+}
+
+impl PrometheusClientMetrics {
+    fn new(
+        metrics: Arc<PrometheusClientMetricDefinitions>,
+        scheme: Scheme,
+        root: String,
+        name: String,
+    ) -> Self {
+        Self {
+            metrics,
+            scheme,
+            root,
+            name,
+        }
+    }
 
-    fn increment_errors_total(&self, scheme: Scheme, op: &'static str, err: ErrorKind) {
+    fn increment_errors_total(&self, op: &'static str, err: ErrorKind) {

Review Comment:
   Hi, I'm thinking about making `OperationLabels` a seperate struct and implement `EncodeLabelSet` for it. For example:
   
   ```rust
   struct OperationLabels {
     scheme: Scheme,
     op: &'static str,
     namespace: Arc<String>,
     root: Arc<String>,
   }
   
   impl EncodeLabelSet for OperationLabels { .. }
   ```
   
   In this way, we can constrct `OperationLabels` and use:
   
   ```rust
   family.get_or_create(&OperationLabels { ... }).inc();
   ```
   
   This design will also avoid unexpected breaking changes like field doesn't match.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #4907:
URL: https://github.com/apache/opendal/pull/4907


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #4907:
URL: https://github.com/apache/opendal/pull/4907#issuecomment-2233025639

   > does this `root` parameter contain the bucket in it?
   
   No. root is the base path for all opendal operations.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1680868886


##########
core/src/layers/prometheus_client.rs:
##########
@@ -183,6 +192,7 @@ impl PrometheusClientMetrics {
             ("scheme", self.scheme.to_string()),
             ("op", op.to_string()),
             ("root", self.root.to_string()),
+            ("name", self.name.to_string()),

Review Comment:
   I prefer keep `name` before `root`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on PR #4907:
URL: https://github.com/apache/opendal/pull/4907#issuecomment-2233019889

   a question I need to confirm about this PR: does this `root` parameter contain the bucket in it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1680873967


##########
core/src/layers/prometheus_client.rs:
##########
@@ -183,6 +192,7 @@ impl PrometheusClientMetrics {
             ("scheme", self.scheme.to_string()),
             ("op", op.to_string()),
             ("root", self.root.to_string()),
+            ("name", self.name.to_string()),

Review Comment:
   fixed, thank you for the suggestion



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1680927390


##########
core/src/layers/prometheus_client.rs:
##########
@@ -159,32 +162,78 @@ impl PrometheusClientMetrics {
             bytes_total,
         }
     }
+}
+
+#[derive(Clone, Debug)]
+struct PrometheusClientMetrics {
+    metrics: Arc<PrometheusClientMetricDefinitions>,
+    scheme: Scheme,
+    root: String,
+    name: String,
+}
+
+impl PrometheusClientMetrics {
+    fn new(
+        metrics: Arc<PrometheusClientMetricDefinitions>,
+        scheme: Scheme,
+        root: String,
+        name: String,
+    ) -> Self {
+        Self {
+            metrics,
+            scheme,
+            root,
+            name,
+        }
+    }
 
-    fn increment_errors_total(&self, scheme: Scheme, op: &'static str, err: ErrorKind) {
+    fn increment_errors_total(&self, op: &'static str, err: ErrorKind) {

Review Comment:
   let me have a try in this pr



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1682078470


##########
core/src/layers/prometheus_client.rs:
##########
@@ -159,32 +162,78 @@ impl PrometheusClientMetrics {
             bytes_total,
         }
     }
+}
+
+#[derive(Clone, Debug)]
+struct PrometheusClientMetrics {
+    metrics: Arc<PrometheusClientMetricDefinitions>,
+    scheme: Scheme,
+    root: String,
+    name: String,
+}
+
+impl PrometheusClientMetrics {
+    fn new(
+        metrics: Arc<PrometheusClientMetricDefinitions>,
+        scheme: Scheme,
+        root: String,
+        name: String,
+    ) -> Self {
+        Self {
+            metrics,
+            scheme,
+            root,
+            name,
+        }
+    }
 
-    fn increment_errors_total(&self, scheme: Scheme, op: &'static str, err: ErrorKind) {
+    fn increment_errors_total(&self, op: &'static str, err: ErrorKind) {

Review Comment:
   i switched to a `Cow<'static, str>` in https://github.com/apache/opendal/pull/4907/commits/daab9db22bb84e25f959a44bb0813c44ae32a504 which helps reduces copy but can not reduce all the copies.
   
   it turns out that we can not simply add lifetime annotations (for the labels like `root` and `namespace` which stored in a singleton struct) in the labels type within promtheus-client, because each metric (with labels together) will be registered into a global registry, which requires the metrics to be `'static`.
   
   (imho it would be better to allow us make the label set as a trait object, which help us decoupling the lifetime and metrics registration, however it's not allowed in prometheus-client yet)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1682121083


##########
core/src/layers/prometheus_client.rs:
##########
@@ -159,32 +162,78 @@ impl PrometheusClientMetrics {
             bytes_total,
         }
     }
+}
+
+#[derive(Clone, Debug)]
+struct PrometheusClientMetrics {
+    metrics: Arc<PrometheusClientMetricDefinitions>,
+    scheme: Scheme,
+    root: String,
+    name: String,
+}
+
+impl PrometheusClientMetrics {
+    fn new(
+        metrics: Arc<PrometheusClientMetricDefinitions>,
+        scheme: Scheme,
+        root: String,
+        name: String,
+    ) -> Self {
+        Self {
+            metrics,
+            scheme,
+            root,
+            name,
+        }
+    }
 
-    fn increment_errors_total(&self, scheme: Scheme, op: &'static str, err: ErrorKind) {
+    fn increment_errors_total(&self, op: &'static str, err: ErrorKind) {

Review Comment:
   makes sense, i've changed them to structs, PTAL



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1682078470


##########
core/src/layers/prometheus_client.rs:
##########
@@ -159,32 +162,78 @@ impl PrometheusClientMetrics {
             bytes_total,
         }
     }
+}
+
+#[derive(Clone, Debug)]
+struct PrometheusClientMetrics {
+    metrics: Arc<PrometheusClientMetricDefinitions>,
+    scheme: Scheme,
+    root: String,
+    name: String,
+}
+
+impl PrometheusClientMetrics {
+    fn new(
+        metrics: Arc<PrometheusClientMetricDefinitions>,
+        scheme: Scheme,
+        root: String,
+        name: String,
+    ) -> Self {
+        Self {
+            metrics,
+            scheme,
+            root,
+            name,
+        }
+    }
 
-    fn increment_errors_total(&self, scheme: Scheme, op: &'static str, err: ErrorKind) {
+    fn increment_errors_total(&self, op: &'static str, err: ErrorKind) {

Review Comment:
   i switched to a `Cow<'static, str>` in https://github.com/apache/opendal/pull/4907/commits/daab9db22bb84e25f959a44bb0813c44ae32a504 which helps reduces copy but can not reduce all the copies.
   
   it turns out that we can not simply add lifetime annotations (for the labels like `root` and `namespace` which stored in a singleton struct) in the labels type within promtheus-client, because each metric (with labels together) will be registered into a global registry, which requires the metrics to be `'static`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1682090099


##########
core/src/layers/prometheus_client.rs:
##########
@@ -159,32 +162,78 @@ impl PrometheusClientMetrics {
             bytes_total,
         }
     }
+}
+
+#[derive(Clone, Debug)]
+struct PrometheusClientMetrics {
+    metrics: Arc<PrometheusClientMetricDefinitions>,
+    scheme: Scheme,
+    root: String,
+    name: String,
+}
+
+impl PrometheusClientMetrics {
+    fn new(
+        metrics: Arc<PrometheusClientMetricDefinitions>,
+        scheme: Scheme,
+        root: String,
+        name: String,
+    ) -> Self {
+        Self {
+            metrics,
+            scheme,
+            root,
+            name,
+        }
+    }
 
-    fn increment_errors_total(&self, scheme: Scheme, op: &'static str, err: ErrorKind) {
+    fn increment_errors_total(&self, op: &'static str, err: ErrorKind) {

Review Comment:
   Hi, I'm thinking about making `OperationLabels` a seperate struct and implement `EncodeLabelSet` for it. For example:
   
   ```rust
   struct OperationLabels {
     scheme: Scheme,
     op: &'static str,
     namespace: Arc<String>,
     root: Arc<String>,
   }
   
   impl EncodeLabelSet for OperationLabels { .. }
   ```
   
   In this way, we can constrct `OperationLabels` and use:
   
   ```rust
   family.get_or_create(&OperationLabels { ... }).inc();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1680888451


##########
core/src/layers/prometheus_client.rs:
##########
@@ -159,32 +162,78 @@ impl PrometheusClientMetrics {
             bytes_total,
         }
     }
+}
+
+#[derive(Clone, Debug)]
+struct PrometheusClientMetrics {
+    metrics: Arc<PrometheusClientMetricDefinitions>,
+    scheme: Scheme,
+    root: String,
+    name: String,
+}
+
+impl PrometheusClientMetrics {
+    fn new(
+        metrics: Arc<PrometheusClientMetricDefinitions>,
+        scheme: Scheme,
+        root: String,
+        name: String,
+    ) -> Self {
+        Self {
+            metrics,
+            scheme,
+            root,
+            name,
+        }
+    }
 
-    fn increment_errors_total(&self, scheme: Scheme, op: &'static str, err: ErrorKind) {
+    fn increment_errors_total(&self, op: &'static str, err: ErrorKind) {

Review Comment:
   I'm thinking of implementing `EncodeLabelSet` directly for our lables to avoid `to_string()` here.
   
   ref: https://docs.rs/prometheus-client/latest/prometheus_client/metrics/family/struct.Family.html#family-with-custom-type-for-performance-andor-type-safety
   
   Would you like to start a new PR for this or just in this PR?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(prometheus-client): add metric label about `root` on using PrometheusClientLayer [opendal]

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #4907:
URL: https://github.com/apache/opendal/pull/4907#discussion_r1682078470


##########
core/src/layers/prometheus_client.rs:
##########
@@ -159,32 +162,78 @@ impl PrometheusClientMetrics {
             bytes_total,
         }
     }
+}
+
+#[derive(Clone, Debug)]
+struct PrometheusClientMetrics {
+    metrics: Arc<PrometheusClientMetricDefinitions>,
+    scheme: Scheme,
+    root: String,
+    name: String,
+}
+
+impl PrometheusClientMetrics {
+    fn new(
+        metrics: Arc<PrometheusClientMetricDefinitions>,
+        scheme: Scheme,
+        root: String,
+        name: String,
+    ) -> Self {
+        Self {
+            metrics,
+            scheme,
+            root,
+            name,
+        }
+    }
 
-    fn increment_errors_total(&self, scheme: Scheme, op: &'static str, err: ErrorKind) {
+    fn increment_errors_total(&self, op: &'static str, err: ErrorKind) {

Review Comment:
   i switched to a `Cow<'static, str>` in https://github.com/apache/opendal/pull/4907/commits/daab9db22bb84e25f959a44bb0813c44ae32a504 which helps reduces copy but can not reduce all the copies.
   
   it turns out that we can not simply add lifetime annotations (for the labels like `root` and `namespace` which stored in a singleton struct) in the labels type within promtheus-client, because each metric (with labels together) will be registered into a global registry, which requires the metrics to be `'static`.
   
   (imho it would be better to allow us make the label set as a trait object in a metric type, which help us decoupling the lifetime and metrics registration, however it's not allowed in prometheus-client yet)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org