forked from knative/test-infra
-
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.
Implement workqueue.MetricsProvider (#678)
The kubernetes workqueue provides a facility for collecting metrics by registering a workqueue.MetricsProvider via workqueue.SetProvider. This change implements that interface to expose the workqueue metrics into opencensus. This is loosely based on some work started by @grantr [here](kubernetes-sigs/controller-runtime@master...grantr:opencensus-replace#diff-bb94124aff8d568cb4e82854c7d44fd1) Fixes: knative/pkg#522
- Loading branch information
1 parent
ed1a121
commit ecb9800
Showing
7 changed files
with
431 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright 2019 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package metrics | ||
|
||
import ( | ||
"context" | ||
"sync/atomic" | ||
|
||
"go.opencensus.io/stats" | ||
"go.opencensus.io/tag" | ||
"k8s.io/client-go/util/workqueue" | ||
) | ||
|
||
type counterMetric struct { | ||
mutators []tag.Mutator | ||
measure *stats.Int64Measure | ||
} | ||
|
||
var ( | ||
_ workqueue.CounterMetric = (*counterMetric)(nil) | ||
) | ||
|
||
// Inc implements CounterMetric | ||
func (m counterMetric) Inc() { | ||
Record(context.Background(), m.measure.M(1), stats.WithTags(m.mutators...)) | ||
} | ||
|
||
type gaugeMetric struct { | ||
mutators []tag.Mutator | ||
measure *stats.Int64Measure | ||
total int64 | ||
} | ||
|
||
var ( | ||
_ workqueue.GaugeMetric = (*gaugeMetric)(nil) | ||
) | ||
|
||
// Inc implements CounterMetric | ||
func (m *gaugeMetric) Inc() { | ||
total := atomic.AddInt64(&m.total, 1) | ||
Record(context.Background(), m.measure.M(total), stats.WithTags(m.mutators...)) | ||
} | ||
|
||
// Dec implements GaugeMetric | ||
func (m *gaugeMetric) Dec() { | ||
total := atomic.AddInt64(&m.total, -1) | ||
Record(context.Background(), m.measure.M(total), stats.WithTags(m.mutators...)) | ||
} | ||
|
||
type floatMetric struct { | ||
mutators []tag.Mutator | ||
measure *stats.Float64Measure | ||
} | ||
|
||
var ( | ||
_ workqueue.SummaryMetric = (*floatMetric)(nil) | ||
) | ||
|
||
// Observe implements SummaryMetric | ||
func (m floatMetric) Observe(v float64) { | ||
Record(context.Background(), m.measure.M(v), stats.WithTags(m.mutators...)) | ||
} |
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
Oops, something went wrong.