Skip to content

Commit 7748675

Browse files
committed
Create dedicated delta package, add tests, and rename distribution -> histogram
Signed-off-by: Kyle Eckhart <[email protected]>
1 parent 5196e13 commit 7748675

11 files changed

+554
-399
lines changed

collectors/delta_counter.go

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

collectors/delta_distribution.go

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

collectors/fnv.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ const (
2323
prime64 = 1099511628211
2424
)
2525

26-
// hashNew initializies a new fnv64a hash value.
27-
func hashNew() uint64 {
26+
// HashNew initializies a new fnv64a hash value.
27+
func HashNew() uint64 {
2828
return offset64
2929
}
3030

31-
// hashAdd adds a string to a fnv64a hash value, returning the updated hash.
32-
func hashAdd(h uint64, s string) uint64 {
31+
// HashAdd adds a string to a fnv64a hash value, returning the updated hash.
32+
func HashAdd(h uint64, s string) uint64 {
3333
for i := 0; i < len(s); i++ {
3434
h ^= uint64(s[i])
3535
h *= prime64

collectors/monitoring_collector.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ type MonitoringCollector struct {
5454
collectorFillMissingLabels bool
5555
monitoringDropDelegatedProjects bool
5656
logger log.Logger
57-
deltaCounterStore DeltaCounterStore
58-
deltaDistributionStore DeltaDistributionStore
57+
counterStore DeltaCounterStore
58+
histogramStore DeltaHistogramStore
5959
aggregateDeltas bool
6060
}
6161

@@ -82,7 +82,17 @@ type MonitoringCollectorOptions struct {
8282
AggregateDeltas bool
8383
}
8484

85-
func NewMonitoringCollector(projectID string, monitoringService *monitoring.Service, opts MonitoringCollectorOptions, logger log.Logger, counterStore DeltaCounterStore, distributionStore DeltaDistributionStore) (*MonitoringCollector, error) {
85+
type DeltaCounterStore interface {
86+
Increment(metricDescriptor *monitoring.MetricDescriptor, currentValue *ConstMetric)
87+
ListMetrics(metricDescriptorName string) []*ConstMetric
88+
}
89+
90+
type DeltaHistogramStore interface {
91+
Increment(metricDescriptor *monitoring.MetricDescriptor, currentValue *HistogramMetric)
92+
ListMetrics(metricDescriptorName string) []*HistogramMetric
93+
}
94+
95+
func NewMonitoringCollector(projectID string, monitoringService *monitoring.Service, opts MonitoringCollectorOptions, logger log.Logger, counterStore DeltaCounterStore, histogramStore DeltaHistogramStore) (*MonitoringCollector, error) {
8696
const subsystem = "monitoring"
8797

8898
apiCallsTotalMetric := prometheus.NewCounter(
@@ -162,8 +172,8 @@ func NewMonitoringCollector(projectID string, monitoringService *monitoring.Serv
162172
collectorFillMissingLabels: opts.FillMissingLabels,
163173
monitoringDropDelegatedProjects: opts.DropDelegatedProjects,
164174
logger: logger,
165-
deltaCounterStore: counterStore,
166-
deltaDistributionStore: distributionStore,
175+
counterStore: counterStore,
176+
histogramStore: histogramStore,
167177
aggregateDeltas: opts.AggregateDeltas,
168178
}
169179

@@ -346,8 +356,8 @@ func (c *MonitoringCollector) reportTimeSeriesMetrics(
346356
timeSeriesMetrics, err := NewTimeSeriesMetrics(metricDescriptor,
347357
ch,
348358
c.collectorFillMissingLabels,
349-
c.deltaCounterStore,
350-
c.deltaDistributionStore,
359+
c.counterStore,
360+
c.histogramStore,
351361
c.aggregateDeltas,
352362
)
353363
if err != nil {

0 commit comments

Comments
 (0)