Skip to content

Commit

Permalink
Fixes unwrap expressions from last optimization.
Browse files Browse the repository at this point in the history
Signed-off-by: Cyril Tovena <[email protected]>
  • Loading branch information
cyriltovena committed Jan 19, 2021
1 parent 070246c commit be01439
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit be01439

Please sign in to comment.