This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into gosec-issues
- Loading branch information
Showing
24 changed files
with
1,546 additions
and
809 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
codecov: | ||
require_ci_to_pass: yes | ||
|
||
ignore: | ||
- "internal/tools/*" | ||
|
||
coverage: | ||
precision: 1 | ||
round: down | ||
range: "70...100" | ||
status: | ||
project: | ||
default: | ||
target: auto | ||
threshold: 0.5% | ||
|
||
comment: | ||
layout: "reach,diff,flags,tree" | ||
behavior: default | ||
require_changes: yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Run CodeCov | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
env: | ||
# Path to where test results will be saved. | ||
TEST_RESULTS: /tmp/test-results | ||
# Default minimum version of Go to support. | ||
DEFAULT_GO_VERSION: 1.15 | ||
jobs: | ||
test-coverage: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: ${{ env.DEFAULT_GO_VERSION }} | ||
- name: Checkout Repo | ||
uses: actions/checkout@v2 | ||
- name: Setup Environment | ||
run: | | ||
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV | ||
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH | ||
- name: Module cache | ||
uses: actions/[email protected] | ||
env: | ||
cache-name: go-mod-cache | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }} | ||
- name: Run coverage tests | ||
run: | | ||
make test-coverage | ||
mkdir $TEST_RESULTS | ||
cp coverage.out $TEST_RESULTS | ||
cp coverage.txt $TEST_RESULTS | ||
cp coverage.html $TEST_RESULTS | ||
- name: Upload coverage report | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
file: ./coverage.txt | ||
fail_ci_if_error: true | ||
verbose: true | ||
- name: Store coverage test output | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: opentelemetry-log-collection-test-output | ||
path: ${{ env.TEST_RESULTS }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ artifacts/* | |
.vscode/* | ||
gen/ | ||
.idea/* | ||
coverage.out | ||
coverage.out.bak | ||
coverage.txt.bak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
// Copyright The OpenTelemetry 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 file | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/open-telemetry/opentelemetry-log-collection/operator" | ||
"github.com/open-telemetry/opentelemetry-log-collection/testutil" | ||
) | ||
|
||
type fileInputBenchmark struct { | ||
name string | ||
paths []string | ||
config func() *InputConfig | ||
} | ||
|
||
type benchFile struct { | ||
*os.File | ||
log func(int) | ||
} | ||
|
||
func simpleTextFile(file *os.File) *benchFile { | ||
line := stringWithLength(49) + "\n" | ||
return &benchFile{ | ||
File: file, | ||
log: func(_ int) { file.WriteString(line) }, | ||
} | ||
} | ||
|
||
func BenchmarkFileInput(b *testing.B) { | ||
cases := []fileInputBenchmark{ | ||
{ | ||
name: "Single", | ||
paths: []string{ | ||
"file0.log", | ||
}, | ||
config: func() *InputConfig { | ||
cfg := NewInputConfig("test_id") | ||
cfg.Include = []string{ | ||
"file0.log", | ||
} | ||
return cfg | ||
}, | ||
}, | ||
{ | ||
name: "Glob", | ||
paths: []string{ | ||
"file0.log", | ||
"file1.log", | ||
"file2.log", | ||
"file3.log", | ||
}, | ||
config: func() *InputConfig { | ||
cfg := NewInputConfig("test_id") | ||
cfg.Include = []string{"file*.log"} | ||
return cfg | ||
}, | ||
}, | ||
{ | ||
name: "MultiGlob", | ||
paths: []string{ | ||
"file0.log", | ||
"file1.log", | ||
"log0.log", | ||
"log1.log", | ||
}, | ||
config: func() *InputConfig { | ||
cfg := NewInputConfig("test_id") | ||
cfg.Include = []string{ | ||
"file*.log", | ||
"log*.log", | ||
} | ||
return cfg | ||
}, | ||
}, | ||
{ | ||
name: "MaxConcurrent", | ||
paths: []string{ | ||
"file0.log", | ||
"file1.log", | ||
"file2.log", | ||
"file3.log", | ||
}, | ||
config: func() *InputConfig { | ||
cfg := NewInputConfig("test_id") | ||
cfg.Include = []string{ | ||
"file*.log", | ||
} | ||
cfg.MaxConcurrentFiles = 1 | ||
return cfg | ||
}, | ||
}, | ||
{ | ||
name: "FngrPrntLarge", | ||
paths: []string{ | ||
"file0.log", | ||
}, | ||
config: func() *InputConfig { | ||
cfg := NewInputConfig("test_id") | ||
cfg.Include = []string{ | ||
"file*.log", | ||
} | ||
cfg.FingerprintSize = 10 * defaultFingerprintSize | ||
return cfg | ||
}, | ||
}, | ||
{ | ||
name: "FngrPrntSmall", | ||
paths: []string{ | ||
"file0.log", | ||
}, | ||
config: func() *InputConfig { | ||
cfg := NewInputConfig("test_id") | ||
cfg.Include = []string{ | ||
"file*.log", | ||
} | ||
cfg.FingerprintSize = defaultFingerprintSize / 10 | ||
return cfg | ||
}, | ||
}, | ||
} | ||
|
||
for _, bench := range cases { | ||
b.Run(bench.name, func(b *testing.B) { | ||
rootDir, err := ioutil.TempDir("", "") | ||
require.NoError(b, err) | ||
|
||
files := []*benchFile{} | ||
for _, path := range bench.paths { | ||
file := openFile(b, filepath.Join(rootDir, path)) | ||
files = append(files, simpleTextFile(file)) | ||
} | ||
|
||
cfg := bench.config() | ||
cfg.OutputIDs = []string{"fake"} | ||
for i, inc := range cfg.Include { | ||
cfg.Include[i] = filepath.Join(rootDir, inc) | ||
} | ||
cfg.StartAt = "beginning" | ||
|
||
ops, err := cfg.Build(testutil.NewBuildContext(b)) | ||
require.NoError(b, err) | ||
op := ops[0] | ||
|
||
fakeOutput := testutil.NewFakeOutput(b) | ||
err = op.SetOutputs([]operator.Operator{fakeOutput}) | ||
require.NoError(b, err) | ||
|
||
// write half the lines before starting | ||
mid := b.N / 2 | ||
for i := 0; i < mid; i++ { | ||
for _, file := range files { | ||
file.log(i) | ||
} | ||
} | ||
|
||
b.ResetTimer() | ||
err = op.Start(testutil.NewMockPersister("test")) | ||
defer op.Stop() | ||
require.NoError(b, err) | ||
|
||
// write the remainder of lines while running | ||
go func() { | ||
for i := mid; i < b.N; i++ { | ||
for _, file := range files { | ||
file.log(i) | ||
} | ||
} | ||
}() | ||
|
||
for i := 0; i < b.N*len(files); i++ { | ||
<-fakeOutput.Received | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.