Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor delta logic for library usage #190

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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