Skip to content

Commit

Permalink
Create dedicated delta package, add tests, and rename distribution ->…
Browse files Browse the repository at this point in the history
… histogram

Signed-off-by: Kyle Eckhart <[email protected]>
  • Loading branch information
kgeckhart committed Jun 9, 2023
1 parent 1ad63c1 commit 95ff3ad
Show file tree
Hide file tree
Showing 11 changed files with 554 additions and 399 deletions.
147 changes: 0 additions & 147 deletions collectors/delta_counter.go

This file was deleted.

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

This file was deleted.

8 changes: 4 additions & 4 deletions collectors/fnv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const (
prime64 = 1099511628211
)

// hashNew initializies a new fnv64a hash value.
func hashNew() uint64 {
// HashNew initializies a new fnv64a hash value.
func HashNew() uint64 {
return offset64
}

// hashAdd adds a string to a fnv64a hash value, returning the updated hash.
func hashAdd(h uint64, s string) uint64 {
// HashAdd adds a string to a fnv64a hash value, returning the updated hash.
func HashAdd(h uint64, s string) uint64 {
for i := 0; i < len(s); i++ {
h ^= uint64(s[i])
h *= prime64
Expand Down
24 changes: 17 additions & 7 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 @@ -401,8 +411,8 @@ func (c *MonitoringCollector) reportTimeSeriesMetrics(
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 95ff3ad

Please sign in to comment.