-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: add query metric http api (#1957)
- Loading branch information
1 parent
85c7f39
commit 37ebd61
Showing
8 changed files
with
339 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed 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, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package api | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
|
||
"github.com/pingcap/pd/server" | ||
) | ||
|
||
type queryMetric struct { | ||
s *server.Server | ||
} | ||
|
||
func newQueryMetric(s *server.Server) *queryMetric { | ||
return &queryMetric{s: s} | ||
} | ||
|
||
func (h *queryMetric) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
metricAddr := h.s.GetConfig().PDServerCfg.MetricStorage | ||
if metricAddr == "" { | ||
http.Error(w, "metric storage doesn't set", http.StatusInternalServerError) | ||
return | ||
} | ||
u, err := url.Parse(metricAddr) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
switch u.Scheme { | ||
case "http", "https": | ||
// Replace the pd path with the prometheus http API path. | ||
r.URL.Path = strings.Replace(r.URL.Path, "pd/api/v1/metric", "api/v1", 1) | ||
newCustomReverseProxies([]url.URL{*u}).ServeHTTP(w, r) | ||
default: | ||
// TODO: Support read data by self after support store metric data in PD/TiKV. | ||
http.Error(w, fmt.Sprintf("schema of metric storage address is no supported, address: %v", metricAddr), http.StatusInternalServerError) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters