Skip to content

Commit

Permalink
Set unique timestamp in lambda-promtail. (#9560)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeschkies authored May 31, 2023
1 parent fd0efe0 commit c9a3ff5
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tools/lambda-promtail/lambda-promtail/cloudtrail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestParseJson(t *testing.T) {
if err != nil {
t.Error(err)
}
gzipReader,err := gzip.NewReader(file)
gzipReader, err := gzip.NewReader(file)
if err != nil {
t.Error(err)
}
Expand Down
3 changes: 2 additions & 1 deletion tools/lambda-promtail/lambda-promtail/cw.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"time"

"github.com/aws/aws-lambda-go/events"
"github.com/grafana/loki/pkg/logproto"
"github.com/prometheus/common/model"

"github.com/grafana/loki/pkg/logproto"
)

func parseCWEvent(ctx context.Context, b *batch, ev *events.CloudwatchLogsEvent) error {
Expand Down
2 changes: 1 addition & 1 deletion tools/lambda-promtail/lambda-promtail/json_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
)

// Stream helps transmit each recordss withing a channel.
// Stream helps transmit each recordss within a channel.
type Stream struct {
records chan Record
}
Expand Down
5 changes: 3 additions & 2 deletions tools/lambda-promtail/lambda-promtail/kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"time"

"github.com/aws/aws-lambda-go/events"
"github.com/grafana/loki/pkg/logproto"
"github.com/prometheus/common/model"

"github.com/grafana/loki/pkg/logproto"
)

func parseKinesisEvent(ctx context.Context, b batchIf, ev *events.KinesisEvent) error {
Expand All @@ -15,7 +16,7 @@ func parseKinesisEvent(ctx context.Context, b batchIf, ev *events.KinesisEvent)
}

for _, record := range ev.Records {
timestamp := time.Unix(record.Kinesis.ApproximateArrivalTimestamp.Unix(),0)
timestamp := time.Unix(record.Kinesis.ApproximateArrivalTimestamp.Unix(), 0)

labels := model.LabelSet{
model.LabelName("__aws_log_type"): model.LabelValue("kinesis"),
Expand Down
3 changes: 2 additions & 1 deletion tools/lambda-promtail/lambda-promtail/kinesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"testing"

"github.com/aws/aws-lambda-go/events"
"github.com/grafana/loki/pkg/logproto"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/pkg/logproto"
)

type MockBatch struct {
Expand Down
2 changes: 1 addition & 1 deletion tools/lambda-promtail/lambda-promtail/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestLambdaPromtail_ExtraLabelsValid(t *testing.T) {
}

func TestLambdaPromtail_ExtraLabelsMissingValue(t *testing.T) {
extraLabels, err := parseExtraLabels("A,a,B,b,C,c,D",false)
extraLabels, err := parseExtraLabels("A,a,B,b,C,c,D", false)
require.Nil(t, extraLabels)
require.Errorf(t, err, invalidExtraLabelsError)
}
Expand Down
3 changes: 2 additions & 1 deletion tools/lambda-promtail/lambda-promtail/promtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"github.com/grafana/dskit/backoff"
"github.com/grafana/loki/pkg/logproto"
"github.com/prometheus/common/model"

"github.com/grafana/loki/pkg/logproto"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions tools/lambda-promtail/lambda-promtail/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
"github.com/aws/aws-lambda-go/events"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/loki/pkg/logproto"
"github.com/prometheus/common/model"

"github.com/grafana/loki/pkg/logproto"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
Expand Down Expand Up @@ -97,7 +98,6 @@ func parseS3Log(ctx context.Context, b *batch, labels map[string]string, obj io.

ls = applyExtraLabels(ls)

timestamp := time.Now()
// extract the timestamp of the nested event and sends the rest as raw json
if labels["type"] == CLOUDTRAIL_LOG_TYPE {
records := make(chan Record)
Expand Down Expand Up @@ -131,6 +131,7 @@ func parseS3Log(ctx context.Context, b *batch, labels map[string]string, obj io.
}

match := timestampRegex.FindStringSubmatch(log_line)
timestamp := time.Now()
if len(match) > 0 {
timestamp, err = time.Parse(time.RFC3339, match[1])
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion tools/lambda-promtail/lambda-promtail/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"testing"

"github.com/aws/aws-lambda-go/events"
"github.com/grafana/loki/pkg/logproto"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/pkg/logproto"
)

func Test_getLabels(t *testing.T) {
Expand Down

0 comments on commit c9a3ff5

Please sign in to comment.