Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Commit 9a15e64

Browse files
committed
Change to single metric with success/failure
1 parent 950bb81 commit 9a15e64

File tree

4 files changed

+9
-83
lines changed

4 files changed

+9
-83
lines changed

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
1818

19-
// Code generated by controller-gen. DO NOT EDIT.
19+
// autogenerated by controller-gen object, do not modify manually
2020

2121
package v1alpha1
2222

controllers/metrics.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ limitations under the License.
1616
package controllers
1717

1818
import (
19+
"time"
20+
1921
"github.com/prometheus/client_golang/prometheus"
2022
"sigs.k8s.io/controller-runtime/pkg/metrics"
2123
)
@@ -28,45 +30,34 @@ const (
2830
var databricksRequestHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
2931
Name: "databricks_request_duration_seconds",
3032
Help: "Duration of upstream calls to Databricks REST service endpoints",
31-
}, []string{"object_type", "action"})
32-
33-
var databricksRequestCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
34-
Name: "databricks_request_total",
35-
Help: "Counter of upstream calls to Databricks REST service endpoints",
3633
}, []string{"object_type", "action", "outcome"})
3734

3835
func init() {
3936
// Register custom metrics with the global prometheus registry
40-
metrics.Registry.MustRegister(databricksRequestHistogram, databricksRequestCounter)
37+
metrics.Registry.MustRegister(databricksRequestHistogram)
4138
}
4239

4340
// NewExecution creates an Execution instance and starts the timer
4441
func NewExecution(objectType string, action string) Execution {
45-
labels := prometheus.Labels{"object_type": objectType, "action": action}
46-
observer := databricksRequestHistogram.With(labels)
47-
timer := prometheus.NewTimer(observer)
48-
4942
return Execution{
50-
timer: *timer,
51-
labels: labels,
43+
begin: time.Now(),
44+
labels: prometheus.Labels{"object_type": objectType, "action": action},
5245
}
5346
}
5447

5548
// Execution tracks state for an API execution for emitting metrics
5649
type Execution struct {
57-
timer prometheus.Timer
50+
begin time.Time
5851
labels prometheus.Labels
5952
}
6053

6154
// Finish is used to log duration and success/failure
6255
func (e *Execution) Finish(err error) {
63-
e.timer.ObserveDuration()
64-
6556
if err == nil {
6657
e.labels["outcome"] = successMetric
6758
} else {
6859
e.labels["outcome"] = failureMetric
6960
}
70-
71-
databricksRequestCounter.With(e.labels).Inc()
61+
duration := time.Since(e.begin)
62+
databricksRequestHistogram.With(e.labels).Observe(duration.Seconds())
7263
}

controllers/metrics_test.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

docs/resources.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ In addition to the standard metrics that kubebuilder provides, the following cus
6565

6666
The `databricks_request_duration_seconds` histogram provides metrics on the duration of calls via the databricks SDK and has the following labels:
6767

68-
|Name|Description|
69-
|-|-|
70-
|`object_type`|The type of object that the call relatest to, e.g. `dcluster`|
71-
|`action`| The action being performed, e.g. `get`, `create`|
72-
73-
The `databricks_request_total` counter provides the total number of calls via the databricks SDK and can be used in `rate` queries to see the rate of successful/failed calls. The labels for this metric are
74-
7568
|Name|Description|
7669
|-|-|
7770
|`object_type`|The type of object that the call relatest to, e.g. `dcluster`|

0 commit comments

Comments
 (0)