-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63560a5
commit 0729d76
Showing
7 changed files
with
181 additions
and
111 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
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,16 @@ | ||
package metrics | ||
|
||
import "context" | ||
|
||
type ctxQueryLabel struct{} | ||
|
||
func WithQueryLabel(ctx context.Context, label string) context.Context { | ||
return context.WithValue(ctx, ctxQueryLabel{}, label) | ||
} | ||
|
||
func queryLabel(ctx context.Context) (label string) { | ||
if label, has := ctx.Value(ctxQueryLabel{}).(string); has { | ||
return label | ||
} | ||
return "" | ||
} |
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 |
---|---|---|
@@ -1,9 +1,46 @@ | ||
package metrics | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/ydb-platform/ydb-go-sdk/v3/trace" | ||
) | ||
|
||
func retry(config Config) (t trace.Retry) { | ||
config = config.WithSystem("retry") | ||
errs := config.CounterVec("errors", "status", "retry_label", "final") | ||
attempts := config.HistogramVec("attempts", []float64{0, 1, 2, 3, 4, 5, 7, 10}, "retry_label") | ||
latency := config.TimerVec("latency", "status", "retry_label") | ||
t.OnRetry = func(info trace.RetryLoopStartInfo) func(trace.RetryLoopIntermediateInfo) func(trace.RetryLoopDoneInfo) { | ||
var ( | ||
label = info.Label | ||
start = time.Now() | ||
) | ||
return func(info trace.RetryLoopIntermediateInfo) func(trace.RetryLoopDoneInfo) { | ||
if info.Error != nil && config.Details()&trace.RetryEvents != 0 { | ||
errs.With(map[string]string{ | ||
"status": errorBrief(info.Error), | ||
"retry_label": label, | ||
"final": "false", | ||
}).Inc() | ||
} | ||
return func(info trace.RetryLoopDoneInfo) { | ||
if config.Details()&trace.RetryEvents != 0 { | ||
attempts.With(map[string]string{ | ||
"retry_label": label, | ||
}).Record(float64(info.Attempts)) | ||
errs.With(map[string]string{ | ||
"status": errorBrief(info.Error), | ||
"retry_label": label, | ||
"final": "true", | ||
}).Inc() | ||
latency.With(map[string]string{ | ||
"status": errorBrief(info.Error), | ||
"retry_label": label, | ||
}).Record(time.Since(start)) | ||
} | ||
} | ||
} | ||
} | ||
return t | ||
} |
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
Oops, something went wrong.