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

Add support for saving local samples as Exponential Histograms #90

Merged
merged 1 commit into from
May 19, 2023
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
25 changes: 25 additions & 0 deletions pkg/api/collectorcontrollerv1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,31 @@ type Level struct {
// written locally to a file for retention.
// The will be set in the "name" field of the SampleList.
RetentionName string `json:"retentionName,omitempty" yaml:"retentionName,omitempty"`

// RetentionExponentialBuckets if RetentionName is specified and the current Operation is a histogram operation
// then this defines an exponential histogram for each resource's raw samples .
RetentionExponentialBuckets map[string]ExponentialBuckets `json:"retentionExponentialBuckets,omitempty" yaml:"retentionExponentialBuckets,omitempty"`
}

// ExponentialBuckets histogram buckets for saving raw samples
type ExponentialBuckets struct {
// MinimumBase is the smallest exponent base that can be used for any histogram
MinimumBase float64 `json:"minimumBase" yaml:"minimumBase"`

// Compression power-of-two level of compression at which buckets from the MinBase are merged together to form larger buckets
// Compression = 0, base=2. This is the basic case.
// Compression < 0, each base2 bucket is subdivided into 2^Compression log scale sub-buckets.
// Compression > 0, every 2^Compression base2 buckets are merged.
Compression int64 `json:"compression" yaml:"compression"`

// ExponentOffset is offset to start bounds for exponential histogram
// base = MinimumBase ^ (2 ^ Compression)
// start bound = base ^ (index + ExponentOffset)
// end bound = base ^ (index + 1 + ExponentOffset)
ExponentOffset int64 `json:"exponentOffset" yaml:"exponentOffset"`

// SaveMaxOnly indicates that only max value should be saved for resource instead of full histogram
SaveMaxOnly bool `json:"saveMaxOnly,omitempty" yaml:"saveMaxOnly,omitempty"`
}

// LabelsMask defines which labels to keep at a level.
Expand Down
245 changes: 223 additions & 22 deletions pkg/collector/api/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions pkg/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,14 +1235,25 @@ func (c *Collector) AggregateAndCollect(
slb.SampleList.MetricName = aggregatedName.String()
slb.SampleList.Name = l.RetentionName
slb.Mask = l.Mask

for mk, mv := range metric.Values {
s := slb.NewSample(mk)
s.Operation = aggregatedName.Operation.String()
s.Level = aggregatedName.Level.String()
slb.AddQuantityValues(s,
aggregatedName.Resource,
aggregatedName.Source, mv...)
// save samples in histogram format
if aggregatedName.Operation == collectorcontrollerv1alpha1.HistogramOperation && l.RetentionExponentialBuckets != nil {
slb.AddHistogramValues(s,
aggregatedName.Resource,
aggregatedName.Source,
l.RetentionExponentialBuckets[aggregatedName.Resource.String()],
mv...)
} else {
slb.AddQuantityValues(s,
aggregatedName.Resource,
aggregatedName.Source, mv...)
}
}

sCh <- slb.SampleList
c.publishTimer("metric_aggregation_per_aggregated_metric", ch, start, "local_save", name.String(), a.Name, l.Name, "aggregated_metric", aggregatedName.String())
}
Expand Down
Loading