-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
205 additions
and
77 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
2 changes: 1 addition & 1 deletion
2
pkg/aws/metrics/collector_test.go → pkg/metrics/aws/collector_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package metrics | ||
package aws | ||
|
||
import ( | ||
"errors" | ||
|
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,39 @@ | ||
package lbc | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"time" | ||
) | ||
|
||
type MetricCollector interface { | ||
// ObservePodReadinessGateReady this metric is useful to determine how fast pods are becoming ready in the load balancer. | ||
// Due to some architectural constraints, we can only emit this metric for pods that are using readiness gates. | ||
ObservePodReadinessGateReady(namespace string, tgbName string, duration time.Duration) | ||
} | ||
|
||
type collector struct { | ||
instruments *instruments | ||
} | ||
|
||
type noOpCollector struct{} | ||
|
||
func (n *noOpCollector) ObservePodReadinessGateReady(_ string, _ string, _ time.Duration) { | ||
} | ||
|
||
func NewCollector(registerer prometheus.Registerer) MetricCollector { | ||
if registerer == nil { | ||
return &noOpCollector{} | ||
} | ||
|
||
instruments := newInstruments(registerer) | ||
return &collector{ | ||
instruments: instruments, | ||
} | ||
} | ||
|
||
func (c *collector) ObservePodReadinessGateReady(namespace string, tgbName string, duration time.Duration) { | ||
c.instruments.podReadinessFlipSeconds.With(prometheus.Labels{ | ||
labelNamespace: namespace, | ||
labelName: tgbName, | ||
}).Observe(duration.Seconds()) | ||
} |
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,38 @@ | ||
package lbc | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const ( | ||
metricSubsystem = "awslbc" | ||
) | ||
|
||
// These metrics are exported to be used in unit test validation. | ||
const ( | ||
// MetricPodReadinessGateReady tracks the time to flip a readiness gate to true | ||
MetricPodReadinessGateReady = "readiness_gate_ready_seconds" | ||
) | ||
|
||
const ( | ||
labelNamespace = "namespace" | ||
labelName = "name" | ||
) | ||
|
||
type instruments struct { | ||
podReadinessFlipSeconds *prometheus.HistogramVec | ||
} | ||
|
||
// newInstruments allocates and register new metrics to registerer | ||
func newInstruments(registerer prometheus.Registerer) *instruments { | ||
podReadinessFlipSeconds := prometheus.NewHistogramVec(prometheus.HistogramOpts{ | ||
Subsystem: metricSubsystem, | ||
Name: MetricPodReadinessGateReady, | ||
Help: "Latency from pod getting added to the load balancer until the readiness gate is flipped to healthy.", | ||
}, []string{labelNamespace, labelName}) | ||
|
||
registerer.MustRegister(podReadinessFlipSeconds) | ||
return &instruments{ | ||
podReadinessFlipSeconds: podReadinessFlipSeconds, | ||
} | ||
} |
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,37 @@ | ||
package lbc | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type MockCollector struct { | ||
Invocations map[string][]interface{} | ||
} | ||
|
||
type MockHistogramMetric struct { | ||
namespace string | ||
name string | ||
duration time.Duration | ||
} | ||
|
||
func (m *MockCollector) ObservePodReadinessGateReady(namespace string, tgbName string, d time.Duration) { | ||
m.recordHistogram(MetricPodReadinessGateReady, namespace, tgbName, d) | ||
} | ||
|
||
func (m *MockCollector) recordHistogram(metricName string, namespace string, name string, d time.Duration) { | ||
m.Invocations[metricName] = append(m.Invocations[MetricPodReadinessGateReady], MockHistogramMetric{ | ||
namespace: namespace, | ||
name: name, | ||
duration: d, | ||
}) | ||
} | ||
|
||
func NewMockCollector() MetricCollector { | ||
|
||
mockInvocations := make(map[string][]interface{}) | ||
mockInvocations[MetricPodReadinessGateReady] = make([]interface{}, 0) | ||
|
||
return &MockCollector{ | ||
Invocations: mockInvocations, | ||
} | ||
} |
Oops, something went wrong.