-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Adds stats to topo #4404
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
Merged
Merged
Adds stats to topo #4404
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3707dc4
Adds stats conn
4278d8e
Adds tests and refactor timings/counts to avoid name collisions
cc708b1
Rename variables for clarity
def30ff
Update license to be vitess authors one
87f35ad
Address code review feedback
ae8d58c
Update name for consistency
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,157 @@ | ||
| /* | ||
| Copyright 2018 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 topo | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "golang.org/x/net/context" | ||
|
|
||
| "vitess.io/vitess/go/stats" | ||
| ) | ||
|
|
||
| var _ Conn = (*StatsConn)(nil) | ||
|
|
||
| var ( | ||
| topoStatsConnTimings = stats.NewMultiTimings( | ||
| "TopologyConnOperations", | ||
| "TopologyConnOperations timings", | ||
| []string{"Operation", "Cell"}) | ||
|
|
||
| topoStatsConnErrors = stats.NewCountersWithMultiLabels( | ||
| "TopologyConnErrors", | ||
| "TopologyConnErrors errors per operation", | ||
| []string{"Operation", "Cell"}) | ||
| ) | ||
|
|
||
| // The StatsConn is a wrapper for a Conn that emits stats for every operation | ||
| type StatsConn struct { | ||
| cell string | ||
| conn Conn | ||
| } | ||
|
|
||
| // NewStatsConn returns a StatsConn | ||
| func NewStatsConn(cell string, conn Conn) *StatsConn { | ||
| return &StatsConn{ | ||
| cell: cell, | ||
| conn: conn, | ||
| } | ||
| } | ||
|
|
||
| // ListDir is part of the Conn interface | ||
| func (st *StatsConn) ListDir(ctx context.Context, dirPath string, full bool) ([]DirEntry, error) { | ||
| startTime := time.Now() | ||
| statsKey := []string{"ListDir", st.cell} | ||
| defer topoStatsConnTimings.Record(statsKey, startTime) | ||
| res, err := st.conn.ListDir(ctx, dirPath, full) | ||
| if err != nil { | ||
| topoStatsConnErrors.Add(statsKey, int64(1)) | ||
| return res, err | ||
| } | ||
| return res, err | ||
| } | ||
|
|
||
| // Create is part of the Conn interface | ||
| func (st *StatsConn) Create(ctx context.Context, filePath string, contents []byte) (Version, error) { | ||
| startTime := time.Now() | ||
| statsKey := []string{"Create", st.cell} | ||
| defer topoStatsConnTimings.Record(statsKey, startTime) | ||
| res, err := st.conn.Create(ctx, filePath, contents) | ||
| if err != nil { | ||
| topoStatsConnErrors.Add(statsKey, int64(1)) | ||
| return res, err | ||
| } | ||
| return res, err | ||
| } | ||
|
|
||
| // Update is part of the Conn interface | ||
| func (st *StatsConn) Update(ctx context.Context, filePath string, contents []byte, version Version) (Version, error) { | ||
| startTime := time.Now() | ||
| statsKey := []string{"Update", st.cell} | ||
| defer topoStatsConnTimings.Record(statsKey, startTime) | ||
| res, err := st.conn.Update(ctx, filePath, contents, version) | ||
| if err != nil { | ||
| topoStatsConnErrors.Add(statsKey, int64(1)) | ||
| return res, err | ||
| } | ||
| return res, err | ||
| } | ||
|
|
||
| // Get is part of the Conn interface | ||
| func (st *StatsConn) Get(ctx context.Context, filePath string) ([]byte, Version, error) { | ||
| startTime := time.Now() | ||
| statsKey := []string{"Get", st.cell} | ||
| defer topoStatsConnTimings.Record(statsKey, startTime) | ||
| bytes, version, err := st.conn.Get(ctx, filePath) | ||
| if err != nil { | ||
| topoStatsConnErrors.Add(statsKey, int64(1)) | ||
| return bytes, version, err | ||
| } | ||
| return bytes, version, err | ||
| } | ||
|
|
||
| // Delete is part of the Conn interface | ||
| func (st *StatsConn) Delete(ctx context.Context, filePath string, version Version) error { | ||
| startTime := time.Now() | ||
| statsKey := []string{"Delete", st.cell} | ||
| defer topoStatsConnTimings.Record(statsKey, startTime) | ||
| err := st.conn.Delete(ctx, filePath, version) | ||
| if err != nil { | ||
| topoStatsConnErrors.Add(statsKey, int64(1)) | ||
| return err | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| // Lock is part of the Conn interface | ||
| func (st *StatsConn) Lock(ctx context.Context, dirPath, contents string) (LockDescriptor, error) { | ||
| startTime := time.Now() | ||
| statsKey := []string{"Lock", st.cell} | ||
| defer topoStatsConnTimings.Record(statsKey, startTime) | ||
| res, err := st.conn.Lock(ctx, dirPath, contents) | ||
| if err != nil { | ||
| topoStatsConnErrors.Add(statsKey, int64(1)) | ||
| return res, err | ||
| } | ||
| return res, err | ||
| } | ||
|
|
||
| // Watch is part of the Conn interface | ||
| func (st *StatsConn) Watch(ctx context.Context, filePath string) (current *WatchData, changes <-chan *WatchData, cancel CancelFunc) { | ||
| startTime := time.Now() | ||
| statsKey := []string{"Watch", st.cell} | ||
| defer topoStatsConnTimings.Record(statsKey, startTime) | ||
| return st.conn.Watch(ctx, filePath) | ||
| } | ||
|
|
||
| // NewMasterParticipation is part of the Conn interface | ||
| func (st *StatsConn) NewMasterParticipation(name, id string) (MasterParticipation, error) { | ||
| startTime := time.Now() | ||
| statsKey := []string{"NewMasterParticipation", st.cell} | ||
| defer topoStatsConnTimings.Record(statsKey, startTime) | ||
| res, err := st.conn.NewMasterParticipation(name, id) | ||
| if err != nil { | ||
| topoStatsConnErrors.Add(statsKey, int64(1)) | ||
| return res, err | ||
| } | ||
| return res, err | ||
| } | ||
|
|
||
| // Close is part of the Conn interface | ||
| func (st *StatsConn) Close() { | ||
| startTime := time.Now() | ||
| statsKey := []string{"Close", st.cell} | ||
| defer topoStatsConnTimings.Record(statsKey, startTime) | ||
| st.conn.Close() | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not sure how much visibility you want into the class of failures but it potentially useful to tag based on the error code. So something like adding:
and then in your error handling (I'm taking some liberty with go for brevity ❤️ ... and also eliding some of the necessary error handling / details)
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.
I think for now I would like to keep the generic error count. I'm mostly interested in tracking general errors as we make the changes from skipping consul agent and talking to consul via the HA proxy vs normal operations.
Should we iterate in the future if we see need for more granularity ?
Uh oh!
There was an error while loading. Please reload this page.
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.
Minor, not strong, objections; presumably something downstream of these calls is logging error codes so we can check aggregation for details if necessary?
My thought here is that if our error counts are non-zero (and we don't know because we don't have telemetry right now, correct?) then moving from non-zero to non-zero as we shift between consul and consul-via-proxy doesn't actually tell us if we've functionally changed the behavior since the type of errors are also important.
Two caveats
stats.CountersWithMultiLabelsis incorrect and it's more effort than just adding a single scoped counter then the effort:(payoff | code noise) ratio changes and it's less compelling for meThat said, if you want, I'm pretty okay pushing this into the the future should we need it.
Uh oh!
There was an error while loading. Please reload this page.
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.
I agree with your reasoning here.
My current understanding is number 1. I'm expecting to have zero errors during normal operations. So thinking it should be ok.