Skip to content

Commit

Permalink
feat(tools/lambda-promtail): not evaluate empty string for drop_labels
Browse files Browse the repository at this point in the history
Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber authored and chaudum committed Nov 6, 2023
1 parent 3086a3b commit c359f37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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 c359f37

Please sign in to comment.