hongkun-Shao commented on code in PR #30875:
URL: https://github.com/apache/doris/pull/30875#discussion_r1482482967


##########
be/src/util/bvar_metrics.h:
##########
@@ -0,0 +1,143 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <bthread/mutex.h>
+#include <bvar/latency_recorder.h>
+#include <bvar/reducer.h>
+#include <bvar/status.h>
+
+#include <map>
+#include <memory>
+#include <string>
+#include <unordered_map>
+
+namespace doris {
+
+enum class BvarMetricType { COUNTER, GAUGE, HISTOGRAM, SUMMARY, UNTYPED };
+enum class BvarMetricUnit {
+    NANOSECONDS,
+    MICROSECONDS,
+    MILLISECONDS,
+    SECONDS,
+    BYTES,
+    ROWS,
+    PERCENT,
+    REQUESTS,
+    OPERATIONS,
+    BLOCKS,
+    ROWSETS,
+    CONNECTIONS,
+    PACKETS,
+    NOUNIT,
+    FILESYSTEM
+};
+
+std::ostream& operator<<(std::ostream& os, BvarMetricType type);
+// const char* unit_name(BvarMetricUnit unit);
+
+using Labels = std::unordered_map<std::string, std::string>;
+
+class BvarMetric {
+public:
+    BvarMetric() = default;
+    virtual ~BvarMetric() = default;
+    BvarMetric(BvarMetric&) = default;
+    BvarMetric(BvarMetricType type, BvarMetricUnit unit, std::string name,
+               std::string description = "", std::string group_name = "", 
Labels labels = Labels(),
+               bool is_core_metric = false)
+            : is_core_metric_(is_core_metric),
+              type_(type),
+              unit_(unit),
+              group_name_(group_name),
+              name_(name),
+              description_(description),
+              labels_(labels) {}
+    virtual std::string to_prometheus(const std::string& registry_name) const 
= 0;
+    // std::string to_json(bool with_tablet_metrics = false) const;
+    // std::string to_core_string() const;
+protected:
+    bool is_core_metric_;
+
+    BvarMetricType type_;
+    BvarMetricUnit unit_;
+
+    // use for expose
+    std::string group_name_; // prefix
+    std::string name_;
+    std::string description_;
+
+    Labels labels_;
+};
+
+// bvar::Adder which support the operation of commutative and associative laws
+template <typename T>
+class BvarAdderMetric : public BvarMetric {
+public:
+    BvarAdderMetric(BvarMetricType type, BvarMetricUnit unit, std::string name,
+                    std::string description = "", std::string group_name = "",
+                    Labels labels = Labels(), bool is_core_metric = false)
+            : BvarMetric(type, unit, name, description, group_name, labels, 
is_core_metric) {
+        // addr::expose_as
+        adder_ = std::make_shared<bvar::Adder<T>>(group_name, name + '_' + 
description);

Review Comment:
   we juse use bvar, don't care the hide/expose, will fix to be `adder_ = 
std::make_shared<bvar::Adder<T>>()`



-- 
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-unsubscr...@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to