Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
comms
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xx network
comms
Commits
4d728934
Commit
4d728934
authored
4 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Implement Metric object
parent
770f527d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
connect/metrics.go
+46
-0
46 additions, 0 deletions
connect/metrics.go
with
46 additions
and
0 deletions
connect/metrics.go
0 → 100644
+
46
−
0
View file @
4d728934
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
// Contains functionality for metric tracking on sending
package
connect
import
"sync/atomic"
type
Metric
struct
{
// Active count of non-excluded errors
// (ie errors we deem important)
errorCounter
*
uint64
}
// Constructor for a Metric object
func
NewMetric
()
*
Metric
{
errCounter
:=
uint64
(
0
)
return
&
Metric
{
errorCounter
:
&
errCounter
,
}
}
// Returns a copy of Metric and resets internal state
func
(
m
*
Metric
)
Get
()
*
Metric
{
metricCopy
:=
m
.
deepCopy
()
atomic
.
StoreUint64
(
m
.
errorCounter
,
0
)
return
metricCopy
}
// Increments the error counter in a thread-safe manner
func
(
m
*
Metric
)
IncrementErrors
()
{
atomic
.
AddUint64
(
m
.
errorCounter
,
1
)
}
// DeepCopy creates a copy of Metric.
func
(
m
*
Metric
)
deepCopy
()
*
Metric
{
newErrCounter
:=
atomic
.
LoadUint64
(
m
.
errorCounter
)
return
&
Metric
{
errorCounter
:
&
newErrCounter
,
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment