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

*: add query metric http api #1957

Merged
merged 11 commits into from
Nov 22, 2019
Merged

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Nov 20, 2019

What problem does this PR solve?

  • Add query metric http api. /pd/api/v1/metric/query.
  • Add metric-query-address config item to indicate the metric query address.

This is for pingcap/tidb#13567 project.

What is changed and how it works?

Currently, PD does not support query metric by itself, so just redirect the metric query to metric-query-address. After PD support storage metric data, PD can handle the query request by itself.

metric-query-address should be dynamic adjustment. Because the user can choose which metric data should be read. So I add this config item in pd-server for dynamic adjustment.

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

Code changes

  • Has configuration change

Side effects
Related changes

@CLAassistant
Copy link

CLAassistant commented Nov 20, 2019

CLA assistant check
All committers have signed the CLA.

@codecov-io
Copy link

codecov-io commented Nov 20, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@c71ec95). Click here to learn what that means.
The diff coverage is 21.05%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1957   +/-   ##
=========================================
  Coverage          ?   77.89%           
=========================================
  Files             ?      171           
  Lines             ?    16894           
  Branches          ?        0           
=========================================
  Hits              ?    13159           
  Misses            ?     2717           
  Partials          ?     1018
Impacted Files Coverage Δ
server/config/config.go 82.05% <ø> (ø)
server/api/router.go 99.08% <100%> (ø)
server/api/metric.go 11.76% <11.76%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c71ec95...225983e. Read the comment docs.

@lhy1024 lhy1024 added the component/api HTTP API. label Nov 20, 2019
## the metric storage is the cluster metric storage. This is use for query metric data.
## Currently we use prometheus as metric storage, we may use PD/TiKV as metric storage later.
## For usability, recommended to temporarily set it to the prometheus address, eg: http://127.0.0.1:9090
metric-storage = ""
Copy link
Member

Choose a reason for hiding this comment

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

It sounds like a kind of storage, but actually it is an address.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ye, I already talk with @lonng , @siddontang, they prefer this. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

how about metric-storage-url?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The usage of metric-storage will not only indicate the url address.

@disksing
Copy link
Contributor

Hi @crazycs520 , you need to update API docs too. See https://github.com/pingcap/pd/blob/master/docs/development.md#changing-apis

@@ -144,6 +144,9 @@ func createRouter(prefix string, svr *server.Server) *mux.Router {
rootRouter.Handle("/api/v1/health", newHealthHandler(svr, rd)).Methods("GET")
rootRouter.Handle("/api/v1/diagnose", newDiagnoseHandler(svr, rd)).Methods("GET")
rootRouter.HandleFunc("/api/v1/ping", func(w http.ResponseWriter, r *http.Request) {}).Methods("GET")
// metric query use to query metric data, the protocol is compatible with prometheus.
rootRouter.Handle("/api/v1/metric/query", newQueryMetric(svr)).Methods("GET", "POST")
Copy link
Contributor

Choose a reason for hiding this comment

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

need to update the API documentation in api.raml.

@disksing disksing added this to the v4.0.0-beta milestone Nov 21, 2019
## the metric storage is the cluster metric storage. This is use for query metric data.
## Currently we use prometheus as metric storage, we may use PD/TiKV as metric storage later.
## For usability, recommended to temporarily set it to the prometheus address, eg: http://127.0.0.1:9090
metric-storage = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

how about metric-storage-url?

@@ -144,6 +144,9 @@ func createRouter(prefix string, svr *server.Server) *mux.Router {
rootRouter.Handle("/api/v1/health", newHealthHandler(svr, rd)).Methods("GET")
rootRouter.Handle("/api/v1/diagnose", newDiagnoseHandler(svr, rd)).Methods("GET")
rootRouter.HandleFunc("/api/v1/ping", func(w http.ResponseWriter, r *http.Request) {}).Methods("GET")
// metric query use to query metric data, the protocol is compatible with prometheus.
rootRouter.Handle("/api/v1/metric/query", newQueryMetric(svr)).Methods("GET", "POST")
rootRouter.Handle("/api/v1/metric/query_range", newQueryMetric(svr)).Methods("GET", "POST")
Copy link
Contributor

Choose a reason for hiding this comment

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

It seem to be more restful to use query-range or range?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lhy1024 query_range is compatible with Prometheus api. https://prometheus.io/docs/prometheus/latest/querying/api/

server/api/metric.go Outdated Show resolved Hide resolved
@winkyao winkyao merged commit 37ebd61 into tikv:master Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/api HTTP API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants