Skip to content

Commit

Permalink
fix(tools/lambda-promtail): Do not evaluate empty string for drop_lab…
Browse files Browse the repository at this point in the history
…els (#11074)

Fixes #11005 

Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber authored Nov 6, 2023
1 parent 3086a3b commit 94169a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* [10727](https://github.com/grafana/loki/pull/10727) **sandeepsukhani** Native otlp ingestion support
* [11051](https://github.com/grafana/loki/pull/11051) Refactor to not use global logger in modules
##### Fixes
* [11074](https://github.com/grafana/loki/pull/11074) **hainenber** Fix panic in lambda-promtail due to mishandling of empty DROP_LABELS env var.

##### Changes

Expand Down
15 changes: 8 additions & 7 deletions tools/lambda-promtail/lambda-promtail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,15 @@ func parseExtraLabels(extraLabelsRaw string, omitPrefix bool) (model.LabelSet, e
func getDropLabels() ([]model.LabelName, error) {
var result []model.LabelName

dropLabelsRaw = os.Getenv("DROP_LABELS")
dropLabelsRawSplit := strings.Split(dropLabelsRaw, ",")
for _, dropLabelRaw := range dropLabelsRawSplit {
dropLabel := model.LabelName(dropLabelRaw)
if !dropLabel.IsValid() {
return []model.LabelName{}, fmt.Errorf("invalid label name %s", dropLabelRaw)
if dropLabelsRaw = os.Getenv("DROP_LABELS"); dropLabelsRaw != "" {
dropLabelsRawSplit := strings.Split(dropLabelsRaw, ",")
for _, dropLabelRaw := range dropLabelsRawSplit {
dropLabel := model.LabelName(dropLabelRaw)
if !dropLabel.IsValid() {
return []model.LabelName{}, fmt.Errorf("invalid label name %s", dropLabelRaw)
}
result = append(result, dropLabel)
}
result = append(result, dropLabel)
}

return result, nil
Expand Down
7 changes: 6 additions & 1 deletion tools/lambda-promtail/lambda-promtail/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func TestLambdaPromtail_TestParseLabelsNoneProvided(t *testing.T) {
}

func TestLambdaPromtail_TestDropLabels(t *testing.T) {
os.Setenv("DROP_LABELS", "A1,A2")
// Simulate default env var set in Terraform
os.Setenv("DROP_LABELS", "")

// Reset the shared global variables
defer func() {
Expand All @@ -48,6 +49,10 @@ func TestLambdaPromtail_TestDropLabels(t *testing.T) {
var err error
dropLabels, err = getDropLabels()
require.Nil(t, err)

os.Setenv("DROP_LABELS", "A1,A2")
dropLabels, err = getDropLabels()
require.Nil(t, err)
require.Contains(t, dropLabels, model.LabelName("A1"))

defaultLabelSet := model.LabelSet{
Expand Down

0 comments on commit 94169a0

Please sign in to comment.