forked from dapr/dapr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "wip: error code monitoring/metric recording""
This reverts commit 44c31be.
- Loading branch information
1 parent
77fc2d7
commit fde1844
Showing
8 changed files
with
90 additions
and
2 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,51 @@ | ||
package diagnostics | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opencensus.io/stats" | ||
"go.opencensus.io/stats/view" | ||
"go.opencensus.io/tag" | ||
|
||
diagUtils "github.com/dapr/dapr/pkg/diagnostics/utils" | ||
) | ||
|
||
type errorCodeMetrics struct { | ||
errorCodeCount *stats.Int64Measure | ||
|
||
appID string | ||
ctx context.Context | ||
enabled bool | ||
} | ||
|
||
func newErrorCodeMetrics() *errorCodeMetrics { | ||
return &errorCodeMetrics{ //nolint:exhaustruct | ||
errorCodeCount: stats.Int64( | ||
"error_code/count", | ||
"Number of times an error with a specific errorcode was encountered.", | ||
stats.UnitDimensionless), | ||
|
||
ctx: context.Background(), | ||
enabled: false, | ||
} | ||
} | ||
|
||
// Init registers the errorcode metrics view. | ||
func (m *errorCodeMetrics) Init(id string) error { | ||
m.enabled = true | ||
m.appID = id | ||
|
||
return view.Register( | ||
diagUtils.NewMeasureView(m.errorCodeCount, []tag.Key{appIDKey, errorCodeKey}, view.Count()), | ||
) | ||
} | ||
|
||
func (m *errorCodeMetrics) RecordErrorCode(code string) { | ||
if m.enabled { | ||
_ = stats.RecordWithTags( | ||
m.ctx, | ||
diagUtils.WithTags(m.errorCodeCount.Name(), appIDKey, m.appID, errorCodeKey, code), | ||
m.errorCodeCount.M(1), | ||
) | ||
} | ||
} |
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