-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promtail: Add compressed files support #6708
Merged
DylanGuedes
merged 37 commits into
grafana:main
from
DylanGuedes:promtail-compressed-support
Sep 27, 2022
Merged
Changes from 15 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
3c8ad6a
Implement new Reader interface.
DylanGuedes 01800fd
Implement Decompresser.
DylanGuedes 9bffe70
Add relevant docstrings.
DylanGuedes 4cf7c1c
Fix positions state reuse.
DylanGuedes 973d66f
Add CHANGELOG entry.
DylanGuedes f94e7e2
Fix calls to .tailers to be .readers instead.
DylanGuedes 86107fe
Merge branch 'main' of github.com:grafana/loki into promtail-compress…
DylanGuedes c6ec76e
Rename decompresser as decompressor.
DylanGuedes 58b5634
Rephrase misreading decompression log message.
DylanGuedes 77d7fe8
Apply suggestions from code review
DylanGuedes e80a2f8
Add to error text all supported extensions.
DylanGuedes 1168d7a
Doesn't ignore scanning errors != io.EOF.
DylanGuedes 459d1cc
Remove empty error checkage.
DylanGuedes 4bedfb2
Use map for finding supported extensions.
DylanGuedes f21b1d5
Merge branch 'main' into promtail-compressed-support
DylanGuedes f6f4c25
Update CHANGELOG.md
DylanGuedes fb299c6
Merge branch 'main' of github.com:grafana/loki into promtail-compress…
DylanGuedes 8204062
Add readLines benchmark.
DylanGuedes ec9339b
Add .zip long scenario to benchmark.
DylanGuedes 043b674
Fix lint.
DylanGuedes 78794dc
Fix lint.
DylanGuedes 9bf1ec4
Fix nocopylocks lint.
DylanGuedes 3a27e05
Rename i to line.
DylanGuedes 794dc33
Merge branch 'main' of github.com:grafana/loki into promtail-compress…
DylanGuedes d99b09e
Remove dupped changelog lines.
DylanGuedes a2c86db
Remove dupped log line.
DylanGuedes a312cb5
Return pointer for noopclient.
DylanGuedes 7f37bea
Start counting lines at 1.
DylanGuedes fd1041c
Drop support for .zip
DylanGuedes edc3b01
Add docs section.
DylanGuedes ba0483e
Test correctness of the gunzip reader.
DylanGuedes c49af30
Apply suggestions from code review
DylanGuedes 30b6934
Link Loki limits.
DylanGuedes 7621ef9
Explain why Promtail doesn't support log rotations.
DylanGuedes fd71e02
Explain why test case scenario is necessary.
DylanGuedes dc57333
Add TODOs for .zip file.
DylanGuedes 84bfeea
Add clarification to decompressing process.
DylanGuedes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,175 @@ | ||
package file | ||
|
||
import ( | ||
"os" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/grafana/loki/clients/pkg/promtail/api" | ||
"github.com/grafana/loki/clients/pkg/promtail/client/fake" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/atomic" | ||
) | ||
|
||
type noopClient struct { | ||
noopChan chan api.Entry | ||
wg sync.WaitGroup | ||
once sync.Once | ||
} | ||
|
||
func (n *noopClient) Chan() chan<- api.Entry { | ||
return n.noopChan | ||
} | ||
|
||
func (n *noopClient) Stop() { | ||
n.once.Do(func() { close(n.noopChan) }) | ||
} | ||
|
||
func newNoopClient() *noopClient { | ||
c := &noopClient{noopChan: make(chan api.Entry)} | ||
c.wg.Add(1) | ||
go func() { | ||
defer c.wg.Done() | ||
for range c.noopChan { | ||
// noop | ||
} | ||
}() | ||
return c | ||
} | ||
|
||
func BenchmarkReadlines(b *testing.B) { | ||
entryHandler := newNoopClient() | ||
|
||
scenarios := []struct { | ||
name string | ||
file string | ||
}{ | ||
{ | ||
name: "2000 lines of log .tar.gz compressed", | ||
file: "test_fixtures/short-access.tar.gz", | ||
}, | ||
{ | ||
name: "100000 lines of log .gz compressed", | ||
file: "test_fixtures/long-access.gz", | ||
}, | ||
} | ||
|
||
for _, tc := range scenarios { | ||
b.Run(tc.name, func(b *testing.B) { | ||
decBase := &decompressor{ | ||
logger: log.NewNopLogger(), | ||
running: atomic.NewBool(false), | ||
handler: entryHandler, | ||
path: tc.file, | ||
} | ||
|
||
for i := 0; i < b.N; i++ { | ||
newDec := decBase | ||
newDec.metrics = NewMetrics(prometheus.NewRegistry()) | ||
newDec.done = make(chan struct{}) | ||
newDec.readLines() | ||
<-newDec.done | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestGigantiqueGunzipFile(t *testing.T) { | ||
file := "test_fixtures/long-access.gz" | ||
handler := fake.New(func() {}) | ||
|
||
d := &decompressor{ | ||
logger: log.NewNopLogger(), | ||
running: atomic.NewBool(false), | ||
handler: handler, | ||
path: file, | ||
done: make(chan struct{}), | ||
metrics: NewMetrics(prometheus.NewRegistry()), | ||
} | ||
|
||
d.readLines() | ||
|
||
<-d.done | ||
time.Sleep(time.Millisecond * 200) | ||
|
||
entries := handler.Received() | ||
require.Equal(t, 100000, len(entries)) | ||
} | ||
|
||
func TestOnelineFiles(t *testing.T) { | ||
DylanGuedes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fileContent, err := os.ReadFile("test_fixtures/onelinelog.log") | ||
require.NoError(t, err) | ||
t.Run("gunzip file", func(t *testing.T) { | ||
file := "test_fixtures/onelinelog.log.gz" | ||
handler := fake.New(func() {}) | ||
|
||
d := &decompressor{ | ||
logger: log.NewNopLogger(), | ||
running: atomic.NewBool(false), | ||
handler: handler, | ||
path: file, | ||
done: make(chan struct{}), | ||
metrics: NewMetrics(prometheus.NewRegistry()), | ||
} | ||
|
||
d.readLines() | ||
|
||
<-d.done | ||
time.Sleep(time.Millisecond * 200) | ||
|
||
entries := handler.Received() | ||
require.Equal(t, 1, len(entries)) | ||
require.Equal(t, string(fileContent), entries[0].Line) | ||
}) | ||
|
||
t.Run("bzip2 file", func(t *testing.T) { | ||
file := "test_fixtures/onelinelog.log.bz2" | ||
handler := fake.New(func() {}) | ||
|
||
d := &decompressor{ | ||
logger: log.NewNopLogger(), | ||
running: atomic.NewBool(false), | ||
handler: handler, | ||
path: file, | ||
done: make(chan struct{}), | ||
metrics: NewMetrics(prometheus.NewRegistry()), | ||
} | ||
|
||
d.readLines() | ||
|
||
<-d.done | ||
time.Sleep(time.Millisecond * 200) | ||
|
||
entries := handler.Received() | ||
require.Equal(t, 1, len(entries)) | ||
require.Equal(t, string(fileContent), entries[0].Line) | ||
}) | ||
|
||
t.Run("tar.gz file", func(t *testing.T) { | ||
file := "test_fixtures/onelinelog.tar.gz" | ||
handler := fake.New(func() {}) | ||
|
||
d := &decompressor{ | ||
logger: log.NewNopLogger(), | ||
running: atomic.NewBool(false), | ||
handler: handler, | ||
path: file, | ||
done: make(chan struct{}), | ||
metrics: NewMetrics(prometheus.NewRegistry()), | ||
} | ||
|
||
d.readLines() | ||
|
||
<-d.done | ||
time.Sleep(time.Millisecond * 200) | ||
|
||
entries := handler.Received() | ||
require.Equal(t, 1, len(entries)) | ||
firstEntry := entries[0] | ||
require.Contains(t, firstEntry.Line, "onelinelog.log") // contains .tar.gz headers | ||
require.Contains(t, firstEntry.Line, `5.202.214.160 - - [26/Jan/2019:19:45:25 +0330] "GET / HTTP/1.1" 200 30975 "https://www.zanbil.ir/" "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0" "-"`) | ||
}) | ||
} |
Binary file not shown.
Binary file not shown.
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 @@ | ||
5.202.214.160 - - [26/Jan/2019:19:45:25 +0330] "GET / HTTP/1.1" 200 30975 "https://www.zanbil.ir/" "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0" "-" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, thanks for catching it. I think those two changelog entries had something wrong but maybe when merging with the main branch something went off. Fixing it 😅