Commit 29086533 authored by Julien Pivotto's avatar Julien Pivotto Committed by Brian Brazil
Browse files

web: use chained WithInstrumentation (#6661)



* web: use chained WithInstrumentation

Requires an update of github.com/prometheus/common
* Update yaml.v2
Signed-off-by: default avatarJulien Pivotto <roidelapluie@inuits.eu>
parent 0f84d5b2
...@@ -33,7 +33,7 @@ require ( ...@@ -33,7 +33,7 @@ require (
github.com/prometheus/alertmanager v0.18.0 github.com/prometheus/alertmanager v0.18.0
github.com/prometheus/client_golang v1.2.0 github.com/prometheus/client_golang v1.2.0
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
github.com/prometheus/common v0.7.0 github.com/prometheus/common v0.8.0
github.com/samuel/go-zookeeper v0.0.0-20190810000440-0ceca61e4d75 github.com/samuel/go-zookeeper v0.0.0-20190810000440-0ceca61e4d75
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
...@@ -49,7 +49,7 @@ require ( ...@@ -49,7 +49,7 @@ require (
google.golang.org/grpc v1.22.1 google.golang.org/grpc v1.22.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6 gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 gopkg.in/fsnotify/fsnotify.v1 v1.4.7
gopkg.in/yaml.v2 v2.2.2 gopkg.in/yaml.v2 v2.2.7
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2 gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2
k8s.io/api v0.0.0-20190813020757-36bff7324fb7 k8s.io/api v0.0.0-20190813020757-36bff7324fb7
k8s.io/apimachinery v0.0.0-20190809020650-423f5d784010 k8s.io/apimachinery v0.0.0-20190809020650-423f5d784010
......
...@@ -308,6 +308,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: ...@@ -308,6 +308,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY=
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
github.com/prometheus/common v0.8.0 h1:bLkjvFe2ZRX1DpcgZcdf7j/+MnusEps5hktST/FHA34=
github.com/prometheus/common v0.8.0/go.mod h1:PC/OgXc+UN7B4ALwvn1yzVZmVwvhXp5JsbBv6wSv6i0=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8=
...@@ -482,6 +484,10 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl ...@@ -482,6 +484,10 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2 h1:XZx7nhd5GMaZpmDaEHFVafUZC7ya0fuo7cSJ3UCKYmM= gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2 h1:XZx7nhd5GMaZpmDaEHFVafUZC7ya0fuo7cSJ3UCKYmM=
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
......
...@@ -53,6 +53,12 @@ func New() *Router { ...@@ -53,6 +53,12 @@ func New() *Router {
// WithInstrumentation returns a router with instrumentation support. // WithInstrumentation returns a router with instrumentation support.
func (r *Router) WithInstrumentation(instrh func(handlerName string, handler http.HandlerFunc) http.HandlerFunc) *Router { func (r *Router) WithInstrumentation(instrh func(handlerName string, handler http.HandlerFunc) http.HandlerFunc) *Router {
if r.instrh != nil {
newInstrh := instrh
instrh = func(handlerName string, handler http.HandlerFunc) http.HandlerFunc {
return newInstrh(handlerName, r.instrh(handlerName, handler))
}
}
return &Router{rtr: r.rtr, prefix: r.prefix, instrh: instrh} return &Router{rtr: r.rtr, prefix: r.prefix, instrh: instrh}
} }
......
...@@ -33,9 +33,10 @@ var ( ...@@ -33,9 +33,10 @@ var (
GoVersion = runtime.Version() GoVersion = runtime.Version()
) )
// NewCollector returns a collector which exports metrics about current version information. // NewCollector returns a collector that exports metrics about current version
func NewCollector(program string) *prometheus.GaugeVec { // information.
buildInfo := prometheus.NewGaugeVec( func NewCollector(program string) prometheus.Collector {
return prometheus.NewGaugeFunc(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: program, Namespace: program,
Name: "build_info", Name: "build_info",
...@@ -43,11 +44,15 @@ func NewCollector(program string) *prometheus.GaugeVec { ...@@ -43,11 +44,15 @@ func NewCollector(program string) *prometheus.GaugeVec {
"A metric with a constant '1' value labeled by version, revision, branch, and goversion from which %s was built.", "A metric with a constant '1' value labeled by version, revision, branch, and goversion from which %s was built.",
program, program,
), ),
ConstLabels: prometheus.Labels{
"version": Version,
"revision": Revision,
"branch": Branch,
"goversion": GoVersion,
},
}, },
[]string{"version", "revision", "branch", "goversion"}, func() float64 { return 1 },
) )
buildInfo.WithLabelValues(Version, Revision, Branch, GoVersion).Set(1)
return buildInfo
} }
// versionInfoTmpl contains the template used by Info. // versionInfoTmpl contains the template used by Info.
......
language: go language: go
go: go:
- 1.4 - "1.4.x"
- 1.5 - "1.5.x"
- 1.6 - "1.6.x"
- 1.7 - "1.7.x"
- 1.8 - "1.8.x"
- 1.9 - "1.9.x"
- tip - "1.10.x"
- "1.11.x"
- "1.12.x"
- "1.13.x"
- "tip"
go_import_path: gopkg.in/yaml.v2 go_import_path: gopkg.in/yaml.v2
...@@ -229,6 +229,10 @@ type decoder struct { ...@@ -229,6 +229,10 @@ type decoder struct {
mapType reflect.Type mapType reflect.Type
terrors []string terrors []string
strict bool strict bool
decodeCount int
aliasCount int
aliasDepth int
} }
var ( var (
...@@ -314,7 +318,43 @@ func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unm ...@@ -314,7 +318,43 @@ func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unm
return out, false, false return out, false, false
} }
const (
// 400,000 decode operations is ~500kb of dense object declarations, or
// ~5kb of dense object declarations with 10000% alias expansion
alias_ratio_range_low = 400000
// 4,000,000 decode operations is ~5MB of dense object declarations, or
// ~4.5MB of dense object declarations with 10% alias expansion
alias_ratio_range_high = 4000000
// alias_ratio_range is the range over which we scale allowed alias ratios
alias_ratio_range = float64(alias_ratio_range_high - alias_ratio_range_low)
)
func allowedAliasRatio(decodeCount int) float64 {
switch {
case decodeCount <= alias_ratio_range_low:
// allow 99% to come from alias expansion for small-to-medium documents
return 0.99
case decodeCount >= alias_ratio_range_high:
// allow 10% to come from alias expansion for very large documents
return 0.10
default:
// scale smoothly from 99% down to 10% over the range.
// this maps to 396,000 - 400,000 allowed alias-driven decodes over the range.
// 400,000 decode operations is ~100MB of allocations in worst-case scenarios (single-item maps).
return 0.99 - 0.89*(float64(decodeCount-alias_ratio_range_low)/alias_ratio_range)
}
}
func (d *decoder) unmarshal(n *node, out reflect.Value) (good bool) { func (d *decoder) unmarshal(n *node, out reflect.Value) (good bool) {
d.decodeCount++
if d.aliasDepth > 0 {
d.aliasCount++
}
if d.aliasCount > 100 && d.decodeCount > 1000 && float64(d.aliasCount)/float64(d.decodeCount) > allowedAliasRatio(d.decodeCount) {
failf("document contains excessive aliasing")
}
switch n.kind { switch n.kind {
case documentNode: case documentNode:
return d.document(n, out) return d.document(n, out)
...@@ -353,7 +393,9 @@ func (d *decoder) alias(n *node, out reflect.Value) (good bool) { ...@@ -353,7 +393,9 @@ func (d *decoder) alias(n *node, out reflect.Value) (good bool) {
failf("anchor '%s' value contains itself", n.value) failf("anchor '%s' value contains itself", n.value)
} }
d.aliases[n] = true d.aliases[n] = true
d.aliasDepth++
good = d.unmarshal(n.alias, out) good = d.unmarshal(n.alias, out)
d.aliasDepth--
delete(d.aliases, n) delete(d.aliases, n)
return good return good
} }
...@@ -746,8 +788,7 @@ func (d *decoder) merge(n *node, out reflect.Value) { ...@@ -746,8 +788,7 @@ func (d *decoder) merge(n *node, out reflect.Value) {
case mappingNode: case mappingNode:
d.unmarshal(n, out) d.unmarshal(n, out)
case aliasNode: case aliasNode:
an, ok := d.doc.anchors[n.value] if n.alias != nil && n.alias.kind != mappingNode {
if ok && an.kind != mappingNode {
failWantMap() failWantMap()
} }
d.unmarshal(n, out) d.unmarshal(n, out)
...@@ -756,8 +797,7 @@ func (d *decoder) merge(n *node, out reflect.Value) { ...@@ -756,8 +797,7 @@ func (d *decoder) merge(n *node, out reflect.Value) {
for i := len(n.children) - 1; i >= 0; i-- { for i := len(n.children) - 1; i >= 0; i-- {
ni := n.children[i] ni := n.children[i]
if ni.kind == aliasNode { if ni.kind == aliasNode {
an, ok := d.doc.anchors[ni.value] if ni.alias != nil && ni.alias.kind != mappingNode {
if ok && an.kind != mappingNode {
failWantMap() failWantMap()
} }
} else if ni.kind != mappingNode { } else if ni.kind != mappingNode {
......
...@@ -81,7 +81,7 @@ func resolvableTag(tag string) bool { ...@@ -81,7 +81,7 @@ func resolvableTag(tag string) bool {
return false return false
} }
var yamlStyleFloat = regexp.MustCompile(`^[-+]?[0-9]*\.?[0-9]+([eE][-+][0-9]+)?$`) var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`)
func resolve(tag string, in string) (rtag string, out interface{}) { func resolve(tag string, in string) (rtag string, out interface{}) {
if !resolvableTag(tag) { if !resolvableTag(tag) {
......
...@@ -634,13 +634,14 @@ func yaml_parser_fetch_more_tokens(parser *yaml_parser_t) bool { ...@@ -634,13 +634,14 @@ func yaml_parser_fetch_more_tokens(parser *yaml_parser_t) bool {
need_more_tokens = true need_more_tokens = true
} else { } else {
// Check if any potential simple key may occupy the head position. // Check if any potential simple key may occupy the head position.
if !yaml_parser_stale_simple_keys(parser) { for i := len(parser.simple_keys) - 1; i >= 0; i-- {
return false
}
for i := range parser.simple_keys {
simple_key := &parser.simple_keys[i] simple_key := &parser.simple_keys[i]
if simple_key.possible && simple_key.token_number == parser.tokens_parsed { if simple_key.token_number < parser.tokens_parsed {
break
}
if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok {
return false
} else if valid && simple_key.token_number == parser.tokens_parsed {
need_more_tokens = true need_more_tokens = true
break break
} }
...@@ -678,11 +679,6 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool { ...@@ -678,11 +679,6 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool {
return false return false
} }
// Remove obsolete potential simple keys.
if !yaml_parser_stale_simple_keys(parser) {
return false
}
// Check the indentation level against the current column. // Check the indentation level against the current column.
if !yaml_parser_unroll_indent(parser, parser.mark.column) { if !yaml_parser_unroll_indent(parser, parser.mark.column) {
return false return false
...@@ -837,29 +833,30 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool { ...@@ -837,29 +833,30 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool {
"found character that cannot start any token") "found character that cannot start any token")
} }
// Check the list of potential simple keys and remove the positions that func yaml_simple_key_is_valid(parser *yaml_parser_t, simple_key *yaml_simple_key_t) (valid, ok bool) {
// cannot contain simple keys anymore. if !simple_key.possible {
func yaml_parser_stale_simple_keys(parser *yaml_parser_t) bool { return false, true
// Check for a potential simple key for each flow level. }
for i := range parser.simple_keys {
simple_key := &parser.simple_keys[i] // The 1.2 specification says:
//
// The specification requires that a simple key // "If the ? indicator is omitted, parsing needs to see past the
// // implicit key to recognize it as such. To limit the amount of
// - is limited to a single line, // lookahead required, the “:” indicator must appear at most 1024
// - is shorter than 1024 characters. // Unicode characters beyond the start of the key. In addition, the key
if simple_key.possible && (simple_key.mark.line < parser.mark.line || simple_key.mark.index+1024 < parser.mark.index) { // is restricted to a single line."
//
// Check if the potential simple key to be removed is required. if simple_key.mark.line < parser.mark.line || simple_key.mark.index+1024 < parser.mark.index {
if simple_key.required { // Check if the potential simple key to be removed is required.
return yaml_parser_set_scanner_error(parser, if simple_key.required {
"while scanning a simple key", simple_key.mark, return false, yaml_parser_set_scanner_error(parser,
"could not find expected ':'") "while scanning a simple key", simple_key.mark,
} "could not find expected ':'")
simple_key.possible = false
} }
simple_key.possible = false
return false, true
} }
return true return true, true
} }
// Check if a simple key may start at the current position and add it if // Check if a simple key may start at the current position and add it if
...@@ -879,8 +876,8 @@ func yaml_parser_save_simple_key(parser *yaml_parser_t) bool { ...@@ -879,8 +876,8 @@ func yaml_parser_save_simple_key(parser *yaml_parser_t) bool {
possible: true, possible: true,
required: required, required: required,
token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head), token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head),
mark: parser.mark,
} }
simple_key.mark = parser.mark
if !yaml_parser_remove_simple_key(parser) { if !yaml_parser_remove_simple_key(parser) {
return false return false
...@@ -906,13 +903,26 @@ func yaml_parser_remove_simple_key(parser *yaml_parser_t) bool { ...@@ -906,13 +903,26 @@ func yaml_parser_remove_simple_key(parser *yaml_parser_t) bool {
return true return true
} }
// max_flow_level limits the flow_level
const max_flow_level = 10000
// Increase the flow level and resize the simple key list if needed. // Increase the flow level and resize the simple key list if needed.
func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool {
// Reset the simple key on the next level. // Reset the simple key on the next level.
parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{}) parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{
possible: false,
required: false,
token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head),
mark: parser.mark,
})
// Increase the flow level. // Increase the flow level.
parser.flow_level++ parser.flow_level++
if parser.flow_level > max_flow_level {
return yaml_parser_set_scanner_error(parser,
"while increasing flow level", parser.simple_keys[len(parser.simple_keys)-1].mark,
fmt.Sprintf("exceeded max depth of %d", max_flow_level))
}
return true return true
} }
...@@ -925,6 +935,9 @@ func yaml_parser_decrease_flow_level(parser *yaml_parser_t) bool { ...@@ -925,6 +935,9 @@ func yaml_parser_decrease_flow_level(parser *yaml_parser_t) bool {
return true return true
} }
// max_indents limits the indents stack size
const max_indents = 10000
// Push the current indentation level to the stack and set the new level // Push the current indentation level to the stack and set the new level
// the current column is greater than the indentation level. In this case, // the current column is greater than the indentation level. In this case,
// append or insert the specified token into the token queue. // append or insert the specified token into the token queue.
...@@ -939,6 +952,11 @@ func yaml_parser_roll_indent(parser *yaml_parser_t, column, number int, typ yaml ...@@ -939,6 +952,11 @@ func yaml_parser_roll_indent(parser *yaml_parser_t, column, number int, typ yaml
// indentation level. // indentation level.
parser.indents = append(parser.indents, parser.indent) parser.indents = append(parser.indents, parser.indent)
parser.indent = column parser.indent = column
if len(parser.indents) > max_indents {
return yaml_parser_set_scanner_error(parser,
"while increasing indent level", parser.simple_keys[len(parser.simple_keys)-1].mark,
fmt.Sprintf("exceeded max depth of %d", max_indents))
}
// Create a token and insert it into the queue. // Create a token and insert it into the queue.
token := yaml_token_t{ token := yaml_token_t{
...@@ -1270,7 +1288,11 @@ func yaml_parser_fetch_value(parser *yaml_parser_t) bool { ...@@ -1270,7 +1288,11 @@ func yaml_parser_fetch_value(parser *yaml_parser_t) bool {
simple_key := &parser.simple_keys[len(parser.simple_keys)-1] simple_key := &parser.simple_keys[len(parser.simple_keys)-1]
// Have we found a simple key? // Have we found a simple key?
if simple_key.possible { if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok {
return false
} else if valid {
// Create the KEY token and insert it into the queue. // Create the KEY token and insert it into the queue.
token := yaml_token_t{ token := yaml_token_t{
typ: yaml_KEY_TOKEN, typ: yaml_KEY_TOKEN,
......
...@@ -89,7 +89,7 @@ func UnmarshalStrict(in []byte, out interface{}) (err error) { ...@@ -89,7 +89,7 @@ func UnmarshalStrict(in []byte, out interface{}) (err error) {
return unmarshal(in, out, true) return unmarshal(in, out, true)
} }
// A Decorder reads and decodes YAML values from an input stream. // A Decoder reads and decodes YAML values from an input stream.
type Decoder struct { type Decoder struct {
strict bool strict bool
parser *parser parser *parser
......
...@@ -274,7 +274,7 @@ github.com/prometheus/client_golang/prometheus/promhttp ...@@ -274,7 +274,7 @@ github.com/prometheus/client_golang/prometheus/promhttp
github.com/prometheus/client_golang/prometheus/testutil github.com/prometheus/client_golang/prometheus/testutil
# github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 # github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
github.com/prometheus/client_model/go github.com/prometheus/client_model/go
# github.com/prometheus/common v0.7.0 # github.com/prometheus/common v0.8.0
github.com/prometheus/common/config github.com/prometheus/common/config
github.com/prometheus/common/expfmt github.com/prometheus/common/expfmt
github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg
...@@ -442,7 +442,7 @@ gopkg.in/alecthomas/kingpin.v2 ...@@ -442,7 +442,7 @@ gopkg.in/alecthomas/kingpin.v2
gopkg.in/fsnotify/fsnotify.v1 gopkg.in/fsnotify/fsnotify.v1
# gopkg.in/inf.v0 v0.9.0 # gopkg.in/inf.v0 v0.9.0
gopkg.in/inf.v0 gopkg.in/inf.v0
# gopkg.in/yaml.v2 v2.2.2 # gopkg.in/yaml.v2 v2.2.7
gopkg.in/yaml.v2 gopkg.in/yaml.v2
# gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2 # gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2
gopkg.in/yaml.v3 gopkg.in/yaml.v3
......
...@@ -254,10 +254,8 @@ func New(logger log.Logger, o *Options) *Handler { ...@@ -254,10 +254,8 @@ func New(logger log.Logger, o *Options) *Handler {
m := newMetrics(o.Registerer) m := newMetrics(o.Registerer)
router := route.New(). router := route.New().
WithInstrumentation(combineInstrumentations( WithInstrumentation(m.instrumentHandler).
m.instrumentHandler, WithInstrumentation(setPathWithPrefix(""))
setPathWithPrefix(""),
))
cwd, err := os.Getwd() cwd, err := os.Getwd()
if err != nil { if err != nil {
...@@ -552,10 +550,8 @@ func (h *Handler) Run(ctx context.Context) error { ...@@ -552,10 +550,8 @@ func (h *Handler) Run(ctx context.Context) error {
level.Info(h.logger).Log("msg", "router prefix", "prefix", h.options.RoutePrefix) level.Info(h.logger).Log("msg", "router prefix", "prefix", h.options.RoutePrefix)
} }
av1 := route.New(). av1 := route.New().
WithInstrumentation(combineInstrumentations( WithInstrumentation(h.metrics.instrumentHandlerWithPrefix("/api/v1")).
h.metrics.instrumentHandlerWithPrefix("/api/v1"), WithInstrumentation(setPathWithPrefix(apiPath + "/v1"))
setPathWithPrefix(apiPath+"/v1"),
))
h.apiV1.Register(av1) h.apiV1.Register(av1)
mux.Handle(apiPath+"/v1/", http.StripPrefix(apiPath+"/v1", av1)) mux.Handle(apiPath+"/v1/", http.StripPrefix(apiPath+"/v1", av1))
...@@ -1118,15 +1114,6 @@ type AlertByStateCount struct { ...@@ -1118,15 +1114,6 @@ type AlertByStateCount struct {
Firing int32 Firing int32
} }
func combineInstrumentations(fs ...func(handlerName string, handler http.HandlerFunc) http.HandlerFunc) func(string, http.HandlerFunc) http.HandlerFunc {
return func(handlerName string, handler http.HandlerFunc) http.HandlerFunc {
for _, f := range fs {
handler = f(handlerName, handler)
}
return handler
}
}
func setPathWithPrefix(prefix string) func(handlerName string, handler http.HandlerFunc) http.HandlerFunc { func setPathWithPrefix(prefix string) func(handlerName string, handler http.HandlerFunc) http.HandlerFunc {
return func(handlerName string, handler http.HandlerFunc) http.HandlerFunc { return func(handlerName string, handler http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment