-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
metrics: change vtbackup_duration_by_phase to binary-valued vtbackup_phase #12973
Changes from 11 commits
19a1176
a2bbaa3
3d076ff
8a7e559
8e759c9
19e1e32
ad61e10
ff22dc3
93c4852
706716f
fb5fe50
d8e54a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to test for vtbackup-specific metrics in an E2E test, used opentsdb plugin and write stats to file for later verification. |
||
Copyright 2023 The Vitess Authors. | ||
|
||
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, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import "vitess.io/vitess/go/stats/opentsdb" | ||
|
||
// This plugin imports opentsdb to register the opentsdb stats backend. | ||
|
||
func init() { | ||
opentsdb.Init("vtbackup") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,29 @@ func (g *GaugesWithSingleLabel) Set(name string, value int64) { | |
g.counters.set(name, value) | ||
} | ||
|
||
// SyncGaugesWithSingleLabel is a GaugesWithSingleLabel that proactively pushes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new |
||
// stats to push-based backends when Set is called. | ||
type SyncGaugesWithSingleLabel struct { | ||
GaugesWithSingleLabel | ||
name string | ||
} | ||
|
||
// NewSyncGaugesWithSingleLabel creates a new SyncGaugesWithSingleLabel. | ||
func NewSyncGaugesWithSingleLabel(name, help, label string, tags ...string) *SyncGaugesWithSingleLabel { | ||
return &SyncGaugesWithSingleLabel{ | ||
GaugesWithSingleLabel: *NewGaugesWithSingleLabel(name, help, label, tags...), | ||
name: name, | ||
} | ||
} | ||
|
||
// Set sets the value of a named gauge. | ||
func (sg *SyncGaugesWithSingleLabel) Set(name string, value int64) { | ||
sg.GaugesWithSingleLabel.Set(name, value) | ||
if sg.name != "" { | ||
_ = pushOne(sg.name, &sg.GaugesWithSingleLabel) | ||
} | ||
} | ||
|
||
// GaugesWithMultiLabels is a CountersWithMultiLabels implementation where | ||
// the values can go up and down. | ||
type GaugesWithMultiLabels struct { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,22 @@ func Publish(name string, v expvar.Var) { | |
publish(name, v) | ||
} | ||
|
||
func pushAll() error { | ||
backend, ok := pushBackends[statsBackend] | ||
if !ok { | ||
return fmt.Errorf("no PushBackend registered with name %s", statsBackend) | ||
} | ||
return backend.PushAll() | ||
} | ||
|
||
func pushOne(name string, v Variable) error { | ||
backend, ok := pushBackends[statsBackend] | ||
if !ok { | ||
return fmt.Errorf("no PushBackend registered with name %s", statsBackend) | ||
} | ||
return backend.PushOne(name, v) | ||
} | ||
|
||
// StringMapFuncWithMultiLabels is a multidimensional string map publisher. | ||
// | ||
// Map keys are compound names made with joining multiple strings with '.', | ||
|
@@ -183,8 +199,10 @@ func publish(name string, v expvar.Var) { | |
// to be pushed to it. It's used to support push-based metrics backends, as expvar | ||
// by default only supports pull-based ones. | ||
type PushBackend interface { | ||
// PushAll pushes all stats from expvar to the backend | ||
// PushAll pushes all stats from expvar to the backend. | ||
PushAll() error | ||
// PushOne pushes a single stat from expvar to the backend. | ||
PushOne(name string, v Variable) error | ||
} | ||
|
||
var pushBackends = make(map[string]PushBackend) | ||
|
@@ -214,13 +232,7 @@ func emitToBackend(emitPeriod *time.Duration) { | |
ticker := time.NewTicker(*emitPeriod) | ||
defer ticker.Stop() | ||
for range ticker.C { | ||
backend, ok := pushBackends[statsBackend] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
if !ok { | ||
log.Errorf("No PushBackend registered with name %s", statsBackend) | ||
return | ||
} | ||
err := backend.PushAll() | ||
if err != nil { | ||
if err := pushAll(); err != nil { | ||
// TODO(aaijazi): This might cause log spam... | ||
log.Warningf("Pushing stats to backend %v failed: %v", statsBackend, err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ended up refactoring this package a bit, mostly moving stuff to their own files. Will call out which stuff was moved vs. new. |
||
Copyright 2023 The Vitess Authors. | ||
|
||
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, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package opentsdb | ||
|
||
import ( | ||
"time" | ||
|
||
"vitess.io/vitess/go/stats" | ||
) | ||
|
||
// backend implements stats.PushBackend | ||
type backend struct { | ||
// The prefix is the name of the binary (vtgate, vttablet, etc.) and will be | ||
// prepended to all the stats reported. | ||
prefix string | ||
// Tags that should be included with every data point. If there's a tag name | ||
// collision between the common tags and a single data point's tags, the data | ||
// point tag will override the common tag. | ||
commonTags map[string]string | ||
// writer is used to send data points somewhere (file, http, ...). | ||
writer writer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new. Factor HTTP-vs.-file specific stats-writing logic into |
||
} | ||
|
||
// PushAll pushes all stats to OpenTSDB | ||
func (b *backend) PushAll() error { | ||
collector := b.collector() | ||
collector.collectAll() | ||
return b.writer.Write(collector.data) | ||
} | ||
|
||
// PushOne pushes a single stat to OpenTSDB | ||
func (b *backend) PushOne(name string, v stats.Variable) error { | ||
collector := b.collector() | ||
collector.collectOne(name, v) | ||
return b.writer.Write(collector.data) | ||
} | ||
|
||
func (b *backend) collector() *collector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new and supports multiple collection strategies ( |
||
return &collector{ | ||
commonTags: b.commonTags, | ||
prefix: b.prefix, | ||
timestamp: time.Now().Unix(), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would have made this Catchup instead of CatchUp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good nit, done!