You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/08/02 11:07:23 UTC
[GitHub] [dubbo-go-pixiu] AlexStocks commented on a diff in pull request #459: feat:Provide unified metrics calculation and reporting implementation
AlexStocks commented on code in PR #459:
URL: https://github.com/apache/dubbo-go-pixiu/pull/459#discussion_r935430804
##########
pkg/metrics/collector/collect.go:
##########
@@ -0,0 +1,78 @@
+package collector
+
+import (
+ "context"
+ "fmt"
+ "github.com/apache/dubbo-go-pixiu/pkg/metrics/global"
+ "github.com/prometheus/client_golang/prometheus"
+ "gopkg.in/alecthomas/kingpin.v2"
+ "log"
+ "net/http"
+ "net/url"
+ "sync"
+)
+
+// Collector is the interface a collector has to implement.
+type Collector interface {
+ // Get new metrics and expose them via prometheus registry.
+ Update(context.Context, chan<- prometheus.Metric) error
+}
+
+type FactoryFunc func(logger log.Logger, u *url.URL, hc *http.Client) (Collector, error)
+
+var (
+ factories = make(map[string]FactoryFunc)
+ initiatedCollectorsMtx = sync.Mutex{}
+ initiatedCollectors = make(map[string]Collector)
+ collectorState = make(map[string]*bool)
+ //collectors which have been explicitly enabled or disabled 明确启用或禁用的收集器
+ forcedCollectors = map[string]bool{}
+)
+
+var (
+ scrapeDurationDesc = prometheus.NewDesc(
+ prometheus.BuildFQName(global.Namespace, "scrape", "duration_seconds"),
+ "pixiu_exporter: Duration of a collector scrape.",
+ []string{"collector"},
+ nil,
+ )
+ scrapeSuccessDesc = prometheus.NewDesc(
+ prometheus.BuildFQName(global.Namespace, "scrape", "success"),
+ "pixiu_exporter: Whether a collector succeeded.",
+ []string{"collector"},
+ nil,
+ )
+)
+
+//供给 collector 调用
Review Comment:
english comment. do not use chinese.
##########
pkg/metrics/collector/collect.go:
##########
@@ -0,0 +1,78 @@
+package collector
+
+import (
+ "context"
+ "fmt"
+ "github.com/apache/dubbo-go-pixiu/pkg/metrics/global"
+ "github.com/prometheus/client_golang/prometheus"
+ "gopkg.in/alecthomas/kingpin.v2"
+ "log"
+ "net/http"
+ "net/url"
+ "sync"
+)
+
+// Collector is the interface a collector has to implement.
+type Collector interface {
+ // Get new metrics and expose them via prometheus registry.
+ Update(context.Context, chan<- prometheus.Metric) error
+}
+
+type FactoryFunc func(logger log.Logger, u *url.URL, hc *http.Client) (Collector, error)
+
+var (
+ factories = make(map[string]FactoryFunc)
+ initiatedCollectorsMtx = sync.Mutex{}
+ initiatedCollectors = make(map[string]Collector)
+ collectorState = make(map[string]*bool)
+ //collectors which have been explicitly enabled or disabled 明确启用或禁用的收集器
+ forcedCollectors = map[string]bool{}
+)
+
+var (
+ scrapeDurationDesc = prometheus.NewDesc(
+ prometheus.BuildFQName(global.Namespace, "scrape", "duration_seconds"),
+ "pixiu_exporter: Duration of a collector scrape.",
+ []string{"collector"},
+ nil,
+ )
+ scrapeSuccessDesc = prometheus.NewDesc(
+ prometheus.BuildFQName(global.Namespace, "scrape", "success"),
+ "pixiu_exporter: Whether a collector succeeded.",
+ []string{"collector"},
+ nil,
+ )
+)
+
+//供给 collector 调用
+func RegisterCollector(name string, isDefaultEnabled bool, createFunc FactoryFunc) {
+ var helpDefaultState string
+ if isDefaultEnabled {
+ helpDefaultState = "enabled"
+ } else {
+ helpDefaultState = "disabled"
+ }
+
+ // Create flag for this collector
+ flagName := fmt.Sprintf("collector.%s", name)
+ flagHelp := fmt.Sprintf("Enable the %s collector (default: %s).", name, helpDefaultState)
+ defaultValue := fmt.Sprintf("%v", isDefaultEnabled)
+ //在解析和验证标志后分派给给定的函数。
Review Comment:
english comment, pls.
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org