fix: remove code duplication on metrics

This commit is contained in:
Richard Ramos 2022-12-17 13:15:55 -04:00
parent 4df6aa98bc
commit d916fbf2bb
No known key found for this signature in database
GPG Key ID: BD36D48BC9FFC88C
1 changed files with 9 additions and 11 deletions

View File

@ -91,16 +91,18 @@ var (
} }
) )
func RecordLightpushError(ctx context.Context, tagType string) { func recordWithTags(ctx context.Context, tagKey tag.Key, tagType string, ms stats.Measurement) {
if err := stats.RecordWithTags(ctx, []tag.Mutator{tag.Insert(ErrorType, tagType)}, LightpushErrors.M(1)); err != nil { if err := stats.RecordWithTags(ctx, []tag.Mutator{tag.Insert(tagKey, tagType)}, ms); err != nil {
utils.Logger().Error("failed to record with tags", zap.Error(err)) utils.Logger().Error("failed to record with tags", zap.Error(err))
} }
} }
func RecordLightpushError(ctx context.Context, tagType string) {
recordWithTags(ctx, ErrorType, tagType, LightpushErrors.M(1))
}
func RecordPeerExchangeError(ctx context.Context, tagType string) { func RecordPeerExchangeError(ctx context.Context, tagType string) {
if err := stats.RecordWithTags(ctx, []tag.Mutator{tag.Insert(ErrorType, tagType)}, PeerExchangeError.M(1)); err != nil { recordWithTags(ctx, ErrorType, tagType, PeerExchangeError.M(1))
utils.Logger().Error("failed to record with tags", zap.Error(err))
}
} }
func RecordMessage(ctx context.Context, tagType string, len int) { func RecordMessage(ctx context.Context, tagType string, len int) {
@ -114,14 +116,10 @@ func RecordStoreQuery(ctx context.Context) {
} }
func RecordStoreError(ctx context.Context, tagType string) { func RecordStoreError(ctx context.Context, tagType string) {
if err := stats.RecordWithTags(ctx, []tag.Mutator{tag.Insert(ErrorType, tagType)}, StoreErrors.M(1)); err != nil { recordWithTags(ctx, ErrorType, tagType, StoreErrors.M(1))
utils.Logger().Error("failed to record with tags", zap.Error(err))
}
} }
func RecordVersion(ctx context.Context, version string, commit string) { func RecordVersion(ctx context.Context, version string, commit string) {
v := fmt.Sprintf("%s-%s", version, commit) v := fmt.Sprintf("%s-%s", version, commit)
if err := stats.RecordWithTags(ctx, []tag.Mutator{tag.Insert(GitVersion, v)}, WakuVersion.M(1)); err != nil { recordWithTags(ctx, GitVersion, v, WakuVersion.M(1))
utils.Logger().Error("failed to record with tags", zap.Error(err))
}
} }