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

feat: collect and serve pre-aggregated bytes and counts #13020

Merged
merged 47 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
dc620e7
feat: collect and serve pre-agg bytes and count
trevorwhitney May 8, 2024
f0d6a92
feat: reject filter queries to /patterns endpoint
trevorwhitney May 23, 2024
68aa188
feat: guard aggregation behavior behind a feature flag
trevorwhitney May 23, 2024
0bfd0ad
Merge branch 'main' into sample-count-and-bytes
trevorwhitney May 23, 2024
b897fc5
fix: ring proxy methods on pattern ring_client
trevorwhitney May 24, 2024
2587657
fix: grouping
trevorwhitney May 24, 2024
6dd77ae
feat: refactor metric samples to be it's own endpoint
trevorwhitney May 31, 2024
eb84303
chore: a bit of cleanup
trevorwhitney May 31, 2024
33ead60
feat: hook up samples endpoint
trevorwhitney May 31, 2024
abb31a8
Merge branch 'main' into sample-count-and-bytes
trevorwhitney May 31, 2024
87f7282
chore: clean up linting
trevorwhitney May 31, 2024
29febb7
chore: make format
trevorwhitney May 31, 2024
cbf9fc0
docs: update docs
trevorwhitney May 31, 2024
6ed195e
fix: nanosecond values in test with non-decimal seconds value
trevorwhitney Jun 3, 2024
7942e57
Merge branch 'main' into sample-count-and-bytes
trevorwhitney Jun 3, 2024
1822b88
fix: formatting
trevorwhitney Jun 3, 2024
35585db
Merge branch 'main' into sample-count-and-bytes
trevorwhitney Jun 3, 2024
81e27a4
Merge branch 'main' into sample-count-and-bytes
trevorwhitney Jun 4, 2024
3a01880
fix: move /explore/query_range case up
trevorwhitney Jun 4, 2024
30c5b90
chore: add metrics and debug logging
trevorwhitney Jun 5, 2024
d94349c
chore: add more debug logging to chunk iteration
trevorwhitney Jun 5, 2024
d3f760b
fix: use pointers for chunks and samples, add chunk locking
trevorwhitney Jun 5, 2024
a2c601e
feat: add sum merge sample iterator
trevorwhitney Jun 11, 2024
e3777bc
Merge branch 'main' into sample-count-and-bytes
trevorwhitney Jun 11, 2024
f1cfd81
test: read metric batch test
trevorwhitney Jun 11, 2024
f42f523
fix: formatting
trevorwhitney Jun 12, 2024
5c0abde
fix: more linting
trevorwhitney Jun 13, 2024
0f7e473
fix: check-mod
trevorwhitney Jun 13, 2024
6cdeeca
Merge branch 'main' into sample-count-and-bytes
trevorwhitney Jun 13, 2024
ac83fcb
fix: mod again
trevorwhitney Jun 13, 2024
e5e23c8
fix: chunk test
trevorwhitney Jun 13, 2024
1664017
Merge branch 'main' into sample-count-and-bytes
trevorwhitney Jun 13, 2024
721e7c1
fix: docs
trevorwhitney Jun 13, 2024
12b3636
fix: logger in sample evaluator tests
trevorwhitney Jun 14, 2024
1133763
chore: more debug logging
trevorwhitney Jun 17, 2024
d59dd4c
use sum merge sample iterator
trevorwhitney Jun 17, 2024
e4b5dd7
more debug logging
trevorwhitney Jun 17, 2024
426d143
more debug logging
trevorwhitney Jun 17, 2024
0c5a436
test: add test coverage around reading batches
trevorwhitney Jun 18, 2024
96cccef
various fixes for building series
cyriltovena Jun 18, 2024
2d13e8a
Removes comments
cyriltovena Jun 18, 2024
74c245d
fix: Prune chunks older than a specified duration and only delete str…
cyriltovena Jun 18, 2024
fefa6b5
test: more test coverage
trevorwhitney Jun 18, 2024
b255b80
Merge branch 'main' into sample-count-and-bytes
trevorwhitney Jun 18, 2024
796d8d9
fix: truncate timestamp to nearest step
trevorwhitney Jun 18, 2024
b2d72a6
fix: tests
trevorwhitney Jun 18, 2024
fa7016b
fix: lint
trevorwhitney Jun 18, 2024
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
5 changes: 5 additions & 0 deletions cmd/loki/loki-local-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ schema_config:
prefix: index_
period: 24h

pattern_ingester:
enabled: true
metric_aggregation:
enabled: true

ruler:
alertmanager_url: http://localhost:9093

Expand Down
18 changes: 16 additions & 2 deletions pkg/logproto/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ func (r *QueryPatternsResponse) UnmarshalJSON(data []byte) error {
var v struct {
Status string `json:"status"`
Data []struct {
Pattern string `json:"pattern"`
Pattern string `json:"pattern,omitempty"`
Labels string `json:"labels,omitempty"`
Samples [][]int64 `json:"samples"`
} `json:"data"`
}
Expand All @@ -174,7 +175,12 @@ func (r *QueryPatternsResponse) UnmarshalJSON(data []byte) error {
for _, s := range d.Samples {
samples = append(samples, &PatternSample{Timestamp: model.TimeFromUnix(s[0]), Value: s[1]})
}
r.Series = append(r.Series, &PatternSeries{Pattern: d.Pattern, Samples: samples})

if pattern := d.Pattern; pattern != "" {
r.Series = append(r.Series, NewPatternSeriesWithPattern(pattern, samples))
} else if labels := d.Labels; labels != "" {
r.Series = append(r.Series, NewPatternSeriesWithLabels(labels, samples))
}
}
return nil
}
Expand All @@ -188,3 +194,11 @@ func (m *ShardsResponse) Merge(other *ShardsResponse) {
m.ChunkGroups = append(m.ChunkGroups, other.ChunkGroups...)
m.Statistics.Merge(other.Statistics)
}

func NewPatternSeriesWithPattern(pattern string, samples []*PatternSample) *PatternSeries {
return &PatternSeries{Identifier: &PatternSeries_Pattern{pattern}, Samples: samples}
}

func NewPatternSeriesWithLabels(labels string, samples []*PatternSample) *PatternSeries {
return &PatternSeries{Identifier: &PatternSeries_Labels{labels}, Samples: samples}
}
69 changes: 69 additions & 0 deletions pkg/logproto/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package logproto
import (
"testing"

"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -40,3 +41,71 @@ func TestShard_SpaceFor(t *testing.T) {
})
}
}

func TestQueryPatternsResponse_UnmarshalJSON(t *testing.T) {
t.Run("unmarshals patterns", func(t *testing.T) {
mockData := []byte(`{
"status": "success",
"data": [
{
"pattern": "foo <*> bar",
"samples": [[1609459200, 10], [1609545600, 15]]
},
{
"pattern": "foo <*> buzz",
"samples": [[1609459200, 20], [1609545600, 25]]
}
]
}`)

expectedSeries := []*PatternSeries{
NewPatternSeriesWithPattern("foo <*> bar", []*PatternSample{
{Timestamp: model.TimeFromUnix(1609459200), Value: 10},
{Timestamp: model.TimeFromUnix(1609545600), Value: 15},
}),
NewPatternSeriesWithPattern("foo <*> buzz", []*PatternSample{
{Timestamp: model.TimeFromUnix(1609459200), Value: 20},
{Timestamp: model.TimeFromUnix(1609545600), Value: 25},
}),
}

r := &QueryPatternsResponse{}
err := r.UnmarshalJSON(mockData)

require.Nil(t, err)
require.Equal(t, expectedSeries, r.Series)
})

t.Run("unmarshals labels", func(t *testing.T) {
mockData := []byte(`{
"status": "success",
"data": [
{
"labels": "{foo=\"bar\"}",
"samples": [[1609459200, 10], [1609545600, 15]]
},
{
"labels": "{foo=\"buzz\"}",
"samples": [[1609459200, 20], [1609545600, 25]]
}
]
}`)

expectedSeries := []*PatternSeries{
NewPatternSeriesWithLabels(`{foo="bar"}`, []*PatternSample{
{Timestamp: model.TimeFromUnix(1609459200), Value: 10},
{Timestamp: model.TimeFromUnix(1609545600), Value: 15},
}),
NewPatternSeriesWithLabels(`{foo="buzz"}`, []*PatternSample{
{Timestamp: model.TimeFromUnix(1609459200), Value: 20},
{Timestamp: model.TimeFromUnix(1609545600), Value: 25},
}),
}

r := &QueryPatternsResponse{}
err := r.UnmarshalJSON(mockData)

require.Nil(t, err)
require.Equal(t, expectedSeries, r.Series)
})
}
Loading
Loading