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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xx network
comms
Commits
daf17c8b
Commit
daf17c8b
authored
Mar 31, 2021
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Modify testing functions for metric
parent
2d0e07fb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
connect/host.go
+2
-2
2 additions, 2 deletions
connect/host.go
connect/metrics.go
+17
-0
17 additions, 0 deletions
connect/metrics.go
with
19 additions
and
2 deletions
connect/host.go
+
2
−
2
View file @
daf17c8b
...
@@ -206,7 +206,7 @@ func (h *Host) isExcludedMetricError(err string) bool {
...
@@ -206,7 +206,7 @@ func (h *Host) isExcludedMetricError(err string) bool {
// Sets the host metrics to an arbitrary value. Used for testing
// Sets the host metrics to an arbitrary value. Used for testing
// purposes only
// purposes only
func
(
h
*
Host
)
SetMetricsTesting
(
errCounter
uint64
,
face
interface
{})
{
func
(
h
*
Host
)
SetMetricsTesting
(
m
*
Metric
,
face
interface
{})
{
// Ensure that this function is only run in testing environments
// Ensure that this function is only run in testing environments
switch
face
.
(
type
)
{
switch
face
.
(
type
)
{
case
*
testing
.
T
,
*
testing
.
M
,
*
testing
.
B
:
case
*
testing
.
T
,
*
testing
.
M
,
*
testing
.
B
:
...
@@ -215,7 +215,7 @@ func (h *Host) SetMetricsTesting(errCounter uint64, face interface{}) {
...
@@ -215,7 +215,7 @@ func (h *Host) SetMetricsTesting(errCounter uint64, face interface{}) {
panic
(
"SetMetricsTesting() can only be used for testing."
)
panic
(
"SetMetricsTesting() can only be used for testing."
)
}
}
h
.
metrics
.
errCounter
=
&
errCounter
h
.
metrics
.
errCounter
=
m
}
}
...
...
This diff is collapsed.
Click to expand it.
connect/metrics.go
+
17
−
0
View file @
daf17c8b
...
@@ -11,6 +11,7 @@ package connect
...
@@ -11,6 +11,7 @@ package connect
import
(
import
(
"sync/atomic"
"sync/atomic"
"testing"
)
)
type
Metric
struct
{
type
Metric
struct
{
...
@@ -27,6 +28,22 @@ func newMetric() *Metric {
...
@@ -27,6 +28,22 @@ func newMetric() *Metric {
}
}
}
}
// Creates a metrics object with specified values. Used for testing
// purposes only
func
NewMetricTesting
(
errCounter
uint64
,
face
interface
{})
*
Metric
{
// Ensure that this function is only run in testing environments
switch
face
.
(
type
)
{
case
*
testing
.
T
,
*
testing
.
M
,
*
testing
.
B
:
break
default
:
panic
(
"SetMetricsTesting() can only be used for testing."
)
}
return
&
Metric
{
errCounter
:
&
errCounter
,
}
}
// Getter for errCounter
// Getter for errCounter
func
(
m
*
Metric
)
GetErrorCounter
()
uint64
{
func
(
m
*
Metric
)
GetErrorCounter
()
uint64
{
return
atomic
.
LoadUint64
(
m
.
errCounter
)
return
atomic
.
LoadUint64
(
m
.
errCounter
)
...
...
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