-
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
lambda-promtail: Add ability to ingest logs from S3 #5065
Changes from 1 commit
fd80dd0
a2fec89
774c5e8
611d604
dc1b849
b42243e
0ab4647
394b6c7
74f88ac
ea56137
8331cc1
373eb18
e57b6f6
bdfda42
5e75cea
df9eceb
5cfd06a
6e5d6a3
3b025ff
227f77c
b99d800
2c241b7
b443ebc
7d3c4f8
370f116
b31063a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,31 +36,44 @@ type entry struct { | |
|
||
type batch struct { | ||
streams map[string]*logproto.Stream | ||
size int | ||
} | ||
|
||
func newBatch(entries ...entry) *batch { | ||
func newBatch(ctx context.Context, entries ...entry) (*batch, error) { | ||
b := &batch{ | ||
streams: map[string]*logproto.Stream{}, | ||
} | ||
|
||
for _, entry := range entries { | ||
b.add(entry) | ||
err := b.add(ctx, entry) | ||
return b, err | ||
} | ||
|
||
return b | ||
return b, nil | ||
} | ||
|
||
func (b *batch) add(e entry) { | ||
func (b *batch) add(ctx context.Context, e entry) error { | ||
labels := labelsMapToString(e.labels, reservedLabelTenantID) | ||
if stream, ok := b.streams[labels]; ok { | ||
stream.Entries = append(stream.Entries, e.entry) | ||
return | ||
|
||
b.size += stream.Size() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, will fix that |
||
|
||
} else { | ||
|
||
b.streams[labels] = &logproto.Stream{ | ||
Labels: labels, | ||
Entries: []logproto.Entry{e.entry}, | ||
} | ||
|
||
b.size += b.streams[labels].Size() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit again: we could simplify to something like this
|
||
} | ||
|
||
b.streams[labels] = &logproto.Stream{ | ||
Labels: labels, | ||
Entries: []logproto.Entry{e.entry}, | ||
if b.size > batchSize { | ||
return b.flushBatch(ctx) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func labelsMapToString(ls model.LabelSet, without ...model.LabelName) string { | ||
AndreZiviani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -103,6 +116,18 @@ func (b *batch) createPushRequest() (*logproto.PushRequest, int) { | |
return &req, entriesCount | ||
} | ||
|
||
func (b *batch) flushBatch(ctx context.Context) error { | ||
fmt.Println("flusing batch") | ||
AndreZiviani marked this conversation as resolved.
Show resolved
Hide resolved
AndreZiviani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
err := sendToPromtail(ctx, b) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
b.streams = make(map[string]*logproto.Stream) | ||
|
||
return nil | ||
} | ||
|
||
func sendToPromtail(ctx context.Context, b *batch) error { | ||
buf, _, err := b.encode() | ||
AndreZiviani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
|
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.
We should not swallow this error. Perhaps
newBatch
shouldn't accept entries and thennewBatch
won't need to return an error.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.
since the batch will always be empty here it should never fail, thats why I ignored it