mirror of https://github.com/status-im/go-waku.git
fix: remove code duplication on metrics
This commit is contained in:
parent
4df6aa98bc
commit
d916fbf2bb
|
@ -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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue