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 09:01:54 UTC

[GitHub] [dubbo-go-pixiu] gongna-au opened a new pull request, #459: feat:Provide unified metrics calculation and reporting implementation

gongna-au opened a new pull request, #459:
URL: https://github.com/apache/dubbo-go-pixiu/pull/459

   <!--  Thanks for sending a pull request! 
   -->
   
   **What this PR does**:
   
   **Which issue(s) this PR fixes**:
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
   -->
   Fixes #433
   
   **Special notes for your reviewer**:
   
   **Does this PR introduce a user-facing change?**:
   <!--
   If no, just write "NONE" in the release-note block below.
   If yes, a release note is required:
   Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
   -->
   ```release-note
   
   ```


-- 
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


[GitHub] [dubbo-go-pixiu] AlexStocks commented on a diff in pull request #459: feat:Provide unified metrics calculation and reporting implementation

Posted by GitBox <gi...@apache.org>.
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


[GitHub] [dubbo-go-pixiu] baerwang commented on a diff in pull request #459: feat:Provide unified metrics calculation and reporting implementation

Posted by GitBox <gi...@apache.org>.
baerwang commented on code in PR #459:
URL: https://github.com/apache/dubbo-go-pixiu/pull/459#discussion_r935375279


##########
pkg/metrics/global/global.go:
##########
@@ -0,0 +1,11 @@
+package global
+
+//主要完成一些公共使用类代码的封装以一些全局关键字的定义。
+import ()
+
+const (
+	// Exporter Namespace.
+	// Namespace将会经常被scrape和collector甚至main调用

Review Comment:
   change english and add field meaning



##########
pkg/metrics/collector/cluster_health.go:
##########
@@ -0,0 +1,336 @@
+package collector
+
+import (
+	"log"
+
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"net/url"
+
+	"path"
+
+	"github.com/apache/dubbo-go-pixiu/pkg/metrics/global"
+	"github.com/prometheus/client_golang/prometheus"
+	"github.com/prometheus/client_golang/prometheus/promhttp"

Review Comment:
   split import style



##########
pkg/metrics/collector/api_health.go:
##########
@@ -0,0 +1,182 @@
+package collector
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/apache/dubbo-go-pixiu/pkg/metrics/global"
+	"github.com/prometheus/client_golang/prometheus"

Review Comment:
   split import style



##########
pkg/metrics/collector/api_health.go:
##########
@@ -0,0 +1,182 @@
+package collector
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/apache/dubbo-go-pixiu/pkg/metrics/global"
+	"github.com/prometheus/client_golang/prometheus"
+	"io/ioutil"
+	"log"
+	"net/http"
+	"net/url"
+	"path"
+)
+
+//很多api的状态

Review Comment:
   change english



##########
pkg/metrics/global/global.go:
##########
@@ -0,0 +1,11 @@
+package global
+
+//主要完成一些公共使用类代码的封装以一些全局关键字的定义。
+import ()

Review Comment:
   del and change english



-- 
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


[GitHub] [dubbo-go-pixiu] gongna-au commented on a diff in pull request #459: feat:Provide unified metrics calculation and reporting implementation

Posted by GitBox <gi...@apache.org>.
gongna-au commented on code in PR #459:
URL: https://github.com/apache/dubbo-go-pixiu/pull/459#discussion_r935379697


##########
pkg/metrics/global/global.go:
##########
@@ -0,0 +1,11 @@
+package global
+
+//主要完成一些公共使用类代码的封装以一些全局关键字的定义。
+import ()

Review Comment:
   OK



-- 
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


[GitHub] [dubbo-go-pixiu] gongna-au closed pull request #459: feat:Provide unified metrics calculation and reporting implementation

Posted by GitBox <gi...@apache.org>.
gongna-au closed pull request #459: feat:Provide unified metrics calculation and reporting implementation
URL: https://github.com/apache/dubbo-go-pixiu/pull/459


-- 
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


[GitHub] [dubbo-go-pixiu] AlexStocks commented on pull request #459: feat:Provide unified metrics calculation and reporting implementation

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on PR #459:
URL: https://github.com/apache/dubbo-go-pixiu/pull/459#issuecomment-1203501432

   @gongna-au pls fix the file confliction.


-- 
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


[GitHub] [dubbo-go-pixiu] baerwang commented on a diff in pull request #459: feat:Provide unified metrics calculation and reporting implementation

Posted by GitBox <gi...@apache.org>.
baerwang commented on code in PR #459:
URL: https://github.com/apache/dubbo-go-pixiu/pull/459#discussion_r935408918


##########
pkg/metrics/collector/api_health.go:
##########
@@ -0,0 +1,182 @@
+package collector

Review Comment:
   add license



-- 
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


[GitHub] [dubbo-go-pixiu] AlexStocks commented on pull request #459: feat:Provide unified metrics calculation and reporting implementation

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on PR #459:
URL: https://github.com/apache/dubbo-go-pixiu/pull/459#issuecomment-1202339699

   @gongna-au pls fix the file confliction.


-- 
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