Skip to content

Commit

Permalink
Fix label matching (#79)
Browse files Browse the repository at this point in the history
* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input

* fix wrong matching lables for stdout input
  • Loading branch information
EvanLjp authored Jan 9, 2022
1 parent 7ac4121 commit 5111ba3
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# prepare ubuntu environment
- name: prepare ubuntu environment
if: matrix.runner == 'ubuntu'
run: sudo apt-get install -y libsystemd-dev
run: sudo apt-get clean && sudo apt-get update && sudo apt-get install -y libsystemd-dev

# prepare windows environment
# https://github.com/actions/virtual-environments/issues/2549
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/static-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
# prepare ubuntu environment
- name: prepare ubuntu environment
if: matrix.runner == 'ubuntu'
run: sudo apt-get install -y libsystemd-dev
run: sudo apt-get clean && sudo apt-get update && sudo apt-get install -y libsystemd-dev


- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
Expand All @@ -48,6 +49,10 @@ jobs:
with:
submodules: true

- name: Copy Lib
if: matrix.runner == 'ubuntu'
run: sudo cp ./pkg/logtail/libPluginAdapter.so /usr/lib/

- name: Check License Header
if: matrix.runner == 'ubuntu'
run: make check-license
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile_whole
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COPY . .

RUN make cgobuild

FROM egistry.cn-beijing.aliyuncs.com/log-service/logtail:v1.0.28.0-582a103-aliyun
FROM registry.cn-beijing.aliyuncs.com/log-service/logtail:v1.0.28.0-582a103-aliyun

RUN rm -f /usr/local/ilogtail/libPluginBase.so

Expand Down
126 changes: 126 additions & 0 deletions plugins/input/docker/logmeta/metric_docker_file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright 2022 iLogtail Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux || windows
// +build linux windows

package logmeta

import (
"github.com/alibaba/ilogtail/plugins/test/mock"

"github.com/stretchr/testify/assert"

"regexp"
"testing"
)

func TestServiceDockerStdout_Init(t *testing.T) {
sds := &InputDockerFile{
IncludeLabel: map[string]string{
"inlabel": "label",
"inlabelreg": "^label$",
},
ExcludeLabel: map[string]string{
"exlabel": "label",
"exlabelreg": "^label$",
},
IncludeEnv: map[string]string{
"inenv": "env",
"inenvreg": "^env$",
},
ExcludeEnv: map[string]string{
"exenv": "env",
"exenvreg": "^env$",
},
IncludeContainerLabel: map[string]string{
"inclabel": "label",
"inclabelreg": "^label$",
},
ExcludeContainerLabel: map[string]string{
"exclabel": "label",
"exclabelreg": "^label$",
},
IncludeK8sLabel: map[string]string{
"inklabel": "label",
"inklabelreg": "^label$",
},
ExcludeK8sLabel: map[string]string{
"exklabel": "label",
"exklabelreg": "^label$",
},
K8sNamespaceRegex: "1",
K8sContainerRegex: "2",
K8sPodRegex: "3",
LogPath: "tets",
}
ctx := mock.NewEmptyContext("project", "store", "config")
_, err := sds.Init(ctx)

assert.Equal(t, map[string]string{
"inlabel": "label",
"inclabel": "label",
}, sds.IncludeLabel)
assert.Equal(t, map[string]string{
"exlabel": "label",
"exclabel": "label",
}, sds.ExcludeLabel)

assert.Equal(t, map[string]*regexp.Regexp{
"inlabelreg": regexp.MustCompile("^label$"),
"inclabelreg": regexp.MustCompile("^label$"),
}, sds.IncludeLabelRegex)
assert.Equal(t, map[string]*regexp.Regexp{
"exlabelreg": regexp.MustCompile("^label$"),
"exclabelreg": regexp.MustCompile("^label$"),
},
sds.ExcludeLabelRegex)

assert.Equal(t, map[string]string{
"inenv": "env",
}, sds.IncludeEnv)
assert.Equal(t, map[string]string{
"exenv": "env",
}, sds.ExcludeEnv)

assert.Equal(t, map[string]*regexp.Regexp{
"inenvreg": regexp.MustCompile("^env$"),
}, sds.IncludeEnvRegex)

assert.Equal(t, map[string]*regexp.Regexp{
"exenvreg": regexp.MustCompile("^env$"),
}, sds.ExcludeEnvRegex)

assert.Equal(t, map[string]string{
"inklabel": "label",
}, sds.K8sFilter.IncludeLabels)

assert.Equal(t, map[string]string{
"exklabel": "label",
}, sds.K8sFilter.ExcludeLabels)

assert.Equal(t, map[string]*regexp.Regexp{
"inklabelreg": regexp.MustCompile("^label$"),
}, sds.K8sFilter.IncludeLabelRegs)

assert.Equal(t, map[string]*regexp.Regexp{
"exklabelreg": regexp.MustCompile("^label$"),
}, sds.K8sFilter.ExcludeLabelRegs)

assert.Equal(t, regexp.MustCompile("3"), sds.K8sFilter.PodReg)
assert.Equal(t, regexp.MustCompile("1"), sds.K8sFilter.NamespaceReg)
assert.Equal(t, regexp.MustCompile("2"), sds.K8sFilter.ContainerReg)

assert.NoError(t, err)
}
2 changes: 1 addition & 1 deletion plugins/input/docker/stdout/input_docker_stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (sds *ServiceDockerStdout) FlushAll(c ilogtail.Collector, firstStart bool)
sds.IncludeLabel, sds.ExcludeLabel,
sds.IncludeLabelRegex, sds.ExcludeLabelRegex,
sds.IncludeEnv, sds.ExcludeEnv,
sds.IncludeLabelRegex, sds.ExcludeEnvRegex,
sds.IncludeEnvRegex, sds.ExcludeEnvRegex,
sds.K8sFilter)
sds.lastUpdateTime = newUpdateTime
if !firstStart && newCount == 0 && delCount == 0 {
Expand Down
122 changes: 122 additions & 0 deletions plugins/input/docker/stdout/input_docker_stdout_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2022 iLogtail Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package stdout

import (
"github.com/alibaba/ilogtail/plugins/test/mock"

"github.com/stretchr/testify/assert"

"regexp"
"testing"
)

func TestServiceDockerStdout_Init(t *testing.T) {
sds := &ServiceDockerStdout{
IncludeLabel: map[string]string{
"inlabel": "label",
"inlabelreg": "^label$",
},
ExcludeLabel: map[string]string{
"exlabel": "label",
"exlabelreg": "^label$",
},
IncludeEnv: map[string]string{
"inenv": "env",
"inenvreg": "^env$",
},
ExcludeEnv: map[string]string{
"exenv": "env",
"exenvreg": "^env$",
},
IncludeContainerLabel: map[string]string{
"inclabel": "label",
"inclabelreg": "^label$",
},
ExcludeContainerLabel: map[string]string{
"exclabel": "label",
"exclabelreg": "^label$",
},
IncludeK8sLabel: map[string]string{
"inklabel": "label",
"inklabelreg": "^label$",
},
ExcludeK8sLabel: map[string]string{
"exklabel": "label",
"exklabelreg": "^label$",
},
K8sNamespaceRegex: "1",
K8sContainerRegex: "2",
K8sPodRegex: "3",
}
ctx := mock.NewEmptyContext("project", "store", "config")
_, err := sds.Init(ctx)

assert.Equal(t, map[string]string{
"inlabel": "label",
"inclabel": "label",
}, sds.IncludeLabel)
assert.Equal(t, map[string]string{
"exlabel": "label",
"exclabel": "label",
}, sds.ExcludeLabel)

assert.Equal(t, map[string]*regexp.Regexp{
"inlabelreg": regexp.MustCompile("^label$"),
"inclabelreg": regexp.MustCompile("^label$"),
}, sds.IncludeLabelRegex)
assert.Equal(t, map[string]*regexp.Regexp{
"exlabelreg": regexp.MustCompile("^label$"),
"exclabelreg": regexp.MustCompile("^label$"),
},
sds.ExcludeLabelRegex)

assert.Equal(t, map[string]string{
"inenv": "env",
}, sds.IncludeEnv)
assert.Equal(t, map[string]string{
"exenv": "env",
}, sds.ExcludeEnv)

assert.Equal(t, map[string]*regexp.Regexp{
"inenvreg": regexp.MustCompile("^env$"),
}, sds.IncludeEnvRegex)

assert.Equal(t, map[string]*regexp.Regexp{
"exenvreg": regexp.MustCompile("^env$"),
}, sds.ExcludeEnvRegex)

assert.Equal(t, map[string]string{
"inklabel": "label",
}, sds.K8sFilter.IncludeLabels)

assert.Equal(t, map[string]string{
"exklabel": "label",
}, sds.K8sFilter.ExcludeLabels)

assert.Equal(t, map[string]*regexp.Regexp{
"inklabelreg": regexp.MustCompile("^label$"),
}, sds.K8sFilter.IncludeLabelRegs)

assert.Equal(t, map[string]*regexp.Regexp{
"exklabelreg": regexp.MustCompile("^label$"),
}, sds.K8sFilter.ExcludeLabelRegs)

assert.Equal(t, regexp.MustCompile("3"), sds.K8sFilter.PodReg)
assert.Equal(t, regexp.MustCompile("1"), sds.K8sFilter.NamespaceReg)
assert.Equal(t, regexp.MustCompile("2"), sds.K8sFilter.ContainerReg)

assert.NoError(t, err)
}
Loading

0 comments on commit 5111ba3

Please sign in to comment.