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

feature: optimise the logic of using prometheus #2429

Merged

Conversation

fengzixu
Copy link
Contributor

@fengzixu fengzixu commented Nov 5, 2018

Signed-off-by: fengzixu [email protected]

Ⅰ. Describe what this PR did

  1. use the custom registry to replace the default.
  2. upgrade the package called client-go of prometheus
  3. add the new dependent package called promhttp
  4. enable metrics about gRPC server

Related to: #2395

Ⅱ. Does this pull request fix one issue?

#2395 #2414

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Ⅳ. Describe how to verify it

First, I complied a new binary pouchd, and I run it with parameters:

 /home/xr/workspace/go-project/src/github.com/alibaba/pouch/bin/pouchd -l tcp://0.0.0.0:4243 -l unix:///var/run/pouchd.sock --enable-cri=true --cri-version=v1alpha2

Second, I visted successfully the url: http://<hostIP>:4243/metrics so that I can capture metrics produced by pouchd.

image

And then, I check some points about metrics:

Is there all metrics was registered successfully?

I saved the result about metrics: https://gist.github.com/fengzixu/ab018bd1d1fa8ddc56a6fe9150d36feb. I picked up some samples and compared with original metrics in code. There is no any difference.

Are the active metrics show commonly after I process some operations ?

I use the command pouch pull nginx to pull a image, and I re-captured the metrics from pouch. The figure of metrics about image has a little increase.

Whether the metrics about gRPC server show commonly?

I started up a k8s cluster together with pouch. And I created some pods. After that I found that the metrics about gRPC between pouchd and kubelet has some figures. It was beneficial for me when I debug this function.

image

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Nov 5, 2018

Codecov Report

Merging #2429 into master will decrease coverage by 0.23%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2429      +/-   ##
==========================================
- Coverage    68.8%   68.57%   -0.24%     
==========================================
  Files         272      272              
  Lines       18159    18175      +16     
==========================================
- Hits        12495    12464      -31     
- Misses       4248     4279      +31     
- Partials     1416     1432      +16
Flag Coverage Δ
#criv1alpha1test 31.54% <100%> (+0.26%) ⬆️
#criv1alpha2test 35.61% <100%> (-0.11%) ⬇️
#integrationtest 39.97% <100%> (-0.13%) ⬇️
#nodee2etest 32.82% <100%> (-0.05%) ⬇️
#unittest 26.52% <0%> (ø) ⬆️
Impacted Files Coverage Δ
apis/server/router.go 85.71% <100%> (ø) ⬆️
apis/metrics/metrics.go 100% <100%> (ø) ⬆️
pkg/utils/metrics/metrics.go 100% <100%> (ø) ⬆️
cri/metrics/metrics.go 100% <100%> (ø) ⬆️
cri/ocicni/cni_manager.go 59.18% <0%> (-12.25%) ⬇️
ctrd/watch.go 75.75% <0%> (-7.58%) ⬇️
cri/stream/portforward/httpstream.go 69.16% <0%> (-6.67%) ⬇️
daemon/mgr/system.go 67.93% <0%> (-5.35%) ⬇️
daemon/mgr/events.go 96.29% <0%> (-3.71%) ⬇️
cri/stream/runtime.go 67.85% <0%> (-2.39%) ⬇️
... and 11 more

@fengzixu
Copy link
Contributor Author

fengzixu commented Nov 5, 2018

@starnop After I developed this PR and thought deeply about metrics of gRPC server. I considered that we should save the gRPC metrics. That was beneficial for developers when they want to develop some functions, which perhaps were associated with communication between kubelet and pouchd.

@fengzixu
Copy link
Contributor Author

fengzixu commented Nov 5, 2018

Request review.

@fengzixu
Copy link
Contributor Author

fengzixu commented Nov 5, 2018

By the way, the main reason I upgrade the package called github.com/prometheus/client_golang/prometheus is that I want to use package called promehttp.

@fuweid
Copy link
Contributor

fuweid commented Nov 6, 2018

By the way, the main reason I upgrade the package called github.com/prometheus/client_golang/prometheus is that I want to use package called promehttp.

Sorry, I din't get the point about this PR. Could you explain more detail about what is good from using customize registry? Thanks

@fengzixu
Copy link
Contributor Author

fengzixu commented Nov 6, 2018

By the way, the main reason I upgrade the package called github.com/prometheus/client_golang/prometheus is that I want to use package called promehttp.

Sorry, I din't get the point about this PR. Could you explain more detail about what is good from using customize registry? Thanks

I describe some details about this PR in #2395. @fuweid

@fuweid
Copy link
Contributor

fuweid commented Nov 6, 2018

According to those comments about DefaultRegisterer, we can know that there is a big risk about using global variant in our code especially in the dependent package. If someone modifies this variant accidentally through some methods written in prometheus. That is a disaster. That is a reason, we should avoid using global variants as much as possible.

Good to know. Thanks

Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1930,4 +1936,4 @@
}
],
"rootPath": "github.com/alibaba/pouch"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There should not be a change, please handle it, THX.

@starnop
Copy link
Contributor

starnop commented Nov 6, 2018

Except for the little problem above, LGTM. Thanks for your contribution. :)

@@ -88,8 +89,8 @@ func initRoute(s *Server) http.Handler {
s.addRoute(r, http.MethodPost, "/networks/{id:.*}/disconnect", s.disconnectNetwork)

// metrics
r.Path(versionMatcher + "/metrics").Methods(http.MethodGet).Handler(prometheus.Handler())
r.Path("/metrics").Methods(http.MethodGet).Handler(prometheus.Handler())
r.Path(versionMatcher + "/metrics").Methods(http.MethodGet).Handler(promhttp.HandlerFor(util_metrics.GetCustomPrometheusRegistry(), promhttp.HandlerOpts{}))
Copy link
Contributor

Choose a reason for hiding this comment

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

How to make the function length short?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Let me fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if you could set the prometheus handler using s.addRoute?
It would be the similar style as the other handler.

1. use the custom registry to replace the default.
2. upgrade the package called client-go of prometheus
3. add the new dependent package called promhttp

Related to:  AliyunContainerService#2395
Signed-off-by:  fengzixu <[email protected]>
@fengzixu
Copy link
Contributor Author

fengzixu commented Nov 6, 2018

@HusterWan @starnop Request review again. I have fixed some problems above.

@@ -63,3 +80,21 @@ func NewLabelTimer(subsystem, name, help string, labels ...string) *prometheus.H
ConstLabels: nil,
}, labels)
}

// GetCustomPrometheusRegistry create a custom resigtry of Prometheus.
func GetCustomPrometheusRegistry() *prometheus.Registry {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use GetPrometheusRegistry here. The Custom is for the prometheus package, not for pouch. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm, that is right. As a developer of pouch, he(she) should not care about custom or default.

@HusterWan
Copy link
Contributor

lgtm

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Nov 6, 2018
@allencloud
Copy link
Collaborator

Thanks for your contribution. @fengzixu

@allencloud allencloud merged commit bc76c24 into AliyunContainerService:master Nov 6, 2018
@fuweid
Copy link
Contributor

fuweid commented Nov 6, 2018

@fengzixu could you follow up to change the name? thanks

@fengzixu
Copy link
Contributor Author

fengzixu commented Nov 6, 2018

@fengzixu could you follow up to change the name? thanks

Sure. I will submit a pr to modify the name. @fuweid

fengzixu added a commit to fengzixu/pouch that referenced this pull request Nov 6, 2018
feature: modify the function name about prometheus registry

1. change function name `GetCustomPrometheusRegistry` to `GetPrometheusRegistry`

Related to: AliyunContainerService#2429
fengzixu added a commit to fengzixu/pouch that referenced this pull request Nov 6, 2018
 feature: modify the function name about prometheus registry

1. change function name `GetCustomPrometheusRegistry` to `GetPrometheusRegistry`

Related to: AliyunContainerService#2429
fengzixu added a commit to fengzixu/pouch that referenced this pull request Nov 6, 2018
feature: modify the function name about prometheus registry

1. change function name `GetCustomPrometheusRegistry` to `GetPrometheusRegistry`

Related to: AliyunContainerService#2429
fuweid pushed a commit that referenced this pull request Nov 6, 2018
feature: modify the function name about prometheus registry

1. change function name `GetCustomPrometheusRegistry` to `GetPrometheusRegistry`

Related to: #2429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
areas/log areas/monitoring kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants