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

Fixes unwrap expressions from last optimization. #3194

Merged
merged 1 commit into from
Jan 20, 2021
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
1 change: 1 addition & 0 deletions pkg/logql/log/metrics_extraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func LabelExtractorWithStages(
expectedLabels = append(expectedLabels, preStage.RequiredLabelNames()...)
expectedLabels = append(expectedLabels, groups...)
expectedLabels = append(expectedLabels, postFilter.RequiredLabelNames()...)
expectedLabels = append(expectedLabels, labelName)
expectedLabels = uniqueString(expectedLabels)
}
return &labelSampleExtractor{
Expand Down
11 changes: 10 additions & 1 deletion pkg/logql/log/metrics_extraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package log
import (
"sort"
"testing"
"time"

"github.com/prometheus/prometheus/pkg/labels"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -126,6 +127,15 @@ func Test_labelSampleExtractor_Extract(t *testing.T) {
}
}

func Test_Extract_ExpectedLabels(t *testing.T) {
ex := mustSampleExtractor(LabelExtractorWithStages("duration", ConvertDuration, []string{"foo"}, false, false, []Stage{NewJSONParser()}, NoopStage))

f, lbs, ok := ex.ForStream(labels.Labels{{Name: "bar", Value: "foo"}}).ProcessString(`{"duration":"20ms","foo":"json"}`)
require.True(t, ok)
require.Equal(t, (20 * time.Millisecond).Seconds(), f)
require.Equal(t, labels.Labels{{Name: "foo", Value: "json"}}, lbs.Labels())
}

func mustSampleExtractor(ex SampleExtractor, err error) SampleExtractor {
if err != nil {
panic(err)
Expand All @@ -134,7 +144,6 @@ func mustSampleExtractor(ex SampleExtractor, err error) SampleExtractor {
}

func TestNewLineSampleExtractor(t *testing.T) {

se, err := NewLineSampleExtractor(CountExtractor, nil, nil, false, false)
require.NoError(t, err)
lbs := labels.Labels{
Expand Down