Skip to content

Commit

Permalink
Refactor delta logic for library usage (#190)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Kochie <[email protected]>
  • Loading branch information
kgeckhart authored Dec 19, 2023
1 parent 8b01e7d commit 8a968dc
Show file tree
Hide file tree
Showing 11 changed files with 608 additions and 460 deletions.
152 changes: 0 additions & 152 deletions collectors/delta_counter.go

This file was deleted.

172 changes: 0 additions & 172 deletions collectors/delta_distribution.go

This file was deleted.

26 changes: 18 additions & 8 deletions collectors/monitoring_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ type MonitoringCollector struct {
collectorFillMissingLabels bool
monitoringDropDelegatedProjects bool
logger log.Logger
deltaCounterStore DeltaCounterStore
deltaDistributionStore DeltaDistributionStore
counterStore DeltaCounterStore
histogramStore DeltaHistogramStore
aggregateDeltas bool
descriptorCache DescriptorCache
}
Expand Down Expand Up @@ -110,7 +110,17 @@ func (d *googleDescriptorCache) Store(prefix string, data []*monitoring.MetricDe
d.inner.Store(prefix, data)
}

func NewMonitoringCollector(projectID string, monitoringService *monitoring.Service, opts MonitoringCollectorOptions, logger log.Logger, counterStore DeltaCounterStore, distributionStore DeltaDistributionStore) (*MonitoringCollector, error) {
type DeltaCounterStore interface {
Increment(metricDescriptor *monitoring.MetricDescriptor, currentValue *ConstMetric)
ListMetrics(metricDescriptorName string) []*ConstMetric
}

type DeltaHistogramStore interface {
Increment(metricDescriptor *monitoring.MetricDescriptor, currentValue *HistogramMetric)
ListMetrics(metricDescriptorName string) []*HistogramMetric
}

func NewMonitoringCollector(projectID string, monitoringService *monitoring.Service, opts MonitoringCollectorOptions, logger log.Logger, counterStore DeltaCounterStore, histogramStore DeltaHistogramStore) (*MonitoringCollector, error) {
const subsystem = "monitoring"

apiCallsTotalMetric := prometheus.NewCounter(
Expand Down Expand Up @@ -200,8 +210,8 @@ func NewMonitoringCollector(projectID string, monitoringService *monitoring.Serv
collectorFillMissingLabels: opts.FillMissingLabels,
monitoringDropDelegatedProjects: opts.DropDelegatedProjects,
logger: logger,
deltaCounterStore: counterStore,
deltaDistributionStore: distributionStore,
counterStore: counterStore,
histogramStore: histogramStore,
aggregateDeltas: opts.AggregateDeltas,
descriptorCache: descriptorCache,
}
Expand Down Expand Up @@ -398,11 +408,11 @@ func (c *MonitoringCollector) reportTimeSeriesMetrics(
var metricValueType prometheus.ValueType
var newestTSPoint *monitoring.Point

timeSeriesMetrics, err := NewTimeSeriesMetrics(metricDescriptor,
timeSeriesMetrics, err := newTimeSeriesMetrics(metricDescriptor,
ch,
c.collectorFillMissingLabels,
c.deltaCounterStore,
c.deltaDistributionStore,
c.counterStore,
c.histogramStore,
c.aggregateDeltas,
)
if err != nil {
Expand Down
Loading

0 comments on commit 8a968dc

Please sign in to comment.