-
Notifications
You must be signed in to change notification settings - Fork 0
KLL Aggregator Implementation #4
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bf7384f
Correct restore/backup telegraf scripts
Andallfor 708a631
wrap kll implementation from precompute engine
Andallfor b6af613
verification and benchmarks
Andallfor 1bae7a5
cleanup
Andallfor 88bb845
move sketch implementation to library
Andallfor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Read data directly from FakePrometheusExporter | ||
| # based off max-throughput-prometheus-client.conf | ||
|
|
||
| [global_tags] | ||
| scenario = "prometheus_inp" | ||
|
|
||
| [agent] | ||
| interval = "1ms" | ||
| flush_interval = "1ms" | ||
| flush_jitter = "0s" | ||
| collection_jitter = "0s" | ||
| round_interval = false | ||
| metric_batch_size = 10000 | ||
| metric_buffer_limit = 500000 | ||
| precision = "1ms" | ||
| debug = true | ||
| logfile = "/tmp/telegraf-prometheus-inp.log" | ||
|
|
||
| [[inputs.prometheus]] | ||
| urls = [ | ||
| "http://localhost:8000/metrics", | ||
| "http://localhost:8001/metrics", | ||
| ] | ||
| metric_version = 2 | ||
| url_tag = "scrape_url" | ||
| name_prefix = "gorilla_local_" | ||
| timeout = "5s" | ||
| interval = "250ms" | ||
| metric_batch_size = 10000 | ||
| metric_buffer_limit = 250000 | ||
|
|
||
| [[inputs.internal]] | ||
| per_instance = true | ||
| collect_gostats = true | ||
|
|
||
| [[outputs.file]] | ||
| files = ["../benchmarks/results/prometheus-inp.lp"] | ||
| data_format = "influx" | ||
| use_batch_format = false | ||
| rotation_interval = "1m" | ||
| rotation_max_size = "50MB" | ||
| rotation_max_archives = 15 | ||
| namepass = ["internal_*"] | ||
|
|
||
| [[outputs.prometheus_client]] | ||
| listen = ":9203" | ||
| path = "/metrics" | ||
| metric_version = 2 | ||
| export_timestamp = true | ||
| expiration_interval = "30s" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [[aggregators.kll]] | ||
| k = 256 | ||
| quantiles = [0.5, 0.99] | ||
| write_seen = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| //go:build !custom || aggregators || aggregators.kll | ||
|
|
||
| package all | ||
|
|
||
| import _ "github.com/influxdata/telegraf/plugins/aggregators/kll" // register plugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| //go:generate ../../../tools/readme_config_includer/generator | ||
| package kll | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "fmt" | ||
| "slices" | ||
| "github.com/influxdata/telegraf" | ||
| "github.com/influxdata/telegraf/plugins/aggregators" | ||
| "github.com/zzylol/go-kll" | ||
| ) | ||
|
|
||
| type quantile struct { | ||
| seen []float64; // for debugging, save the seen values | ||
| sketch *kll.Sketch; | ||
| } | ||
|
|
||
| type metric struct { | ||
| name string; | ||
| fields map[string]*quantile; | ||
| } | ||
|
|
||
| type KLL struct { | ||
| K int `toml:"k"`; | ||
| Quantiles []float64 `toml:"quantiles"`; | ||
| WriteSeen bool `toml:"write_seen"`; | ||
|
|
||
| cache map[uint64]*metric; // state for each metric/field, key is metric.HashID() | ||
| suffixes map[float64]string; // suffix to attach to output quantiles, e.g.. _p50, _p99, ... | ||
| } | ||
|
|
||
| //go:embed sample.conf | ||
| var sampleConfig string | ||
| func (*KLL) SampleConfig() string { return sampleConfig; } | ||
|
|
||
| func (k *KLL) Init() error { | ||
| if k.K < 2 { return fmt.Errorf("Invalid Argument. k must be >= 2 (k=%d)", k.K); } | ||
|
|
||
| k.cache = make(map[uint64]*metric); | ||
| k.suffixes = make(map[float64]string); | ||
| for _, q := range k.Quantiles { | ||
| if q < 0 || q > 1 { return fmt.Errorf("Invalid Argument. Quantiles must be in [0, 1] (q=%f)", q); } | ||
| k.suffixes[q] = fmt.Sprintf("_p%d", int(q * 100)); | ||
| } | ||
|
|
||
| return nil; | ||
| } | ||
|
|
||
| // for each numeric field in each metric, update the backing KLL sketch | ||
| func (k *KLL) Add(in telegraf.Metric) { | ||
| var id uint64 = in.HashID(); | ||
|
|
||
| // get saved metric | ||
| m, ok := k.cache[id]; | ||
| if !ok { | ||
| k.cache[id] = &metric{name: in.Name(), fields: make(map[string]*quantile)}; | ||
| m = k.cache[id]; | ||
| } | ||
|
|
||
| // for each field, get associated sketch | ||
| var fields []*telegraf.Field = in.FieldList(); | ||
| for _, field := range fields { | ||
| var val float64; | ||
|
|
||
| // conversion referenced from minmax aggregator | ||
| switch field.Value.(type) { | ||
| case float64: | ||
| val = field.Value.(float64); | ||
| case int64: | ||
| val = float64(field.Value.(int64)); | ||
| case uint64: | ||
| val = float64(field.Value.(uint64)); | ||
| default: | ||
| continue; | ||
| } | ||
|
|
||
| // get sketch | ||
| sketch, ok := m.fields[field.Key]; | ||
| if !ok { | ||
| m.fields[field.Key] = &quantile{seen: nil, sketch: kll.New(k.K)}; | ||
| if k.WriteSeen { m.fields[field.Key].seen = make([]float64, 0); } | ||
|
|
||
| sketch = m.fields[field.Key]; | ||
| } | ||
|
|
||
| if k.WriteSeen { sketch.seen = append(sketch.seen, val); } | ||
|
|
||
| sketch.sketch.Update(val); | ||
| } | ||
| } | ||
|
|
||
| func (k *KLL) Push(acc telegraf.Accumulator) { | ||
| for _, m := range k.cache { | ||
| out := make(map[string]any); | ||
|
|
||
| fields := m.fields; | ||
| for name, sketch := range fields { | ||
| // get the desired quantile | ||
| cdf := sketch.sketch.CDF(); | ||
| for q, str := range k.suffixes { out[name + str] = cdf.Query(q); } | ||
|
|
||
| if k.WriteSeen { | ||
| slices.Sort(sketch.seen) | ||
| out[name + "_seen"] = fmt.Sprintf("%v", sketch.seen); | ||
| } | ||
| } | ||
|
|
||
| acc.AddSummary(m.name + "_KLL", out, nil); | ||
| } | ||
| } | ||
|
|
||
| func (k *KLL) Reset() { | ||
| for _, m := range k.cache { | ||
| for key := range m.fields { | ||
| if k.WriteSeen { clear(m.fields[key].seen); } | ||
| m.fields[key].sketch = kll.New(k.K); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func init() { | ||
| aggregators.Add("kll", func() telegraf.Aggregator { return &KLL{}; }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Outputs quantiles for each numeric field for each metric | ||
| # Aggregated metric has name <base metric>_KLL | ||
| [[aggregators.kll]] | ||
| ## Size of topmost compactor | ||
| ## Total memory used by sketch is 3*k + lg(n) | ||
| k = 256 | ||
|
|
||
| ## Quantiles to retrieve. Must be in range [0, 1] and float (e.g. 0 must be 0.0) | ||
| ## Values will be output as field_p<quantile * 100>, e.g. cpu_p50 | ||
| quantiles = [0.5, 0.99] | ||
|
|
||
| ## Debugging option to also output the sorted ingested values (with suffix _seen) | ||
| write_seen = false |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.