Skip to content
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: no need for GCP promtail_instance label now that loki supports out-of-order writes #4556

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions clients/pkg/promtail/targets/gcplog/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"cloud.google.com/go/pubsub"
"github.com/gofrs/uuid"
json "github.com/json-iterator/go"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
Expand All @@ -18,16 +17,6 @@ import (
"github.com/grafana/loki/pkg/util"
)

var instanceID uuid.UUID

func init() {
id, err := uuid.NewV4()
if err != nil {
panic(err)
}
instanceID = id
}

// LogEntry that will be written to the pubsub topic.
// According to the following spec.
// https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
Expand Down Expand Up @@ -66,14 +55,6 @@ func format(
lbs := labels.NewBuilder(nil)
lbs.Set("resource_type", ge.Resource.Type)

// `promtail_instance` uniquely identifies each promtail instance trying
// to scrape gcplog(from single subscription_id).
//
// We need this unique identifier to avoid out-of-order errors from Loki servers.
// Because say two promtail instances rewrite timestamp of log entries(with same labelset)
// at the same time may reach Loki servers at different times can cause Loki servers to reject it.
lbs.Set("promtail_instance", instanceID.String())

// labels from gcp log entry. Add it as internal labels
for k, v := range ge.Resource.Labels {
lbs.Set("__"+util.SnakeCase(k), v)
Expand Down
11 changes: 4 additions & 7 deletions clients/pkg/promtail/targets/gcplog/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func TestFormat(t *testing.T) {
"resource_type": "gcs",
"backend_service_name": "http-loki",
"bucket_name": "loki-bucket",
"promtail_instance": model.LabelValue(instanceID.String()),
},
Entry: logproto.Entry{
Timestamp: mustTime(t, "2020-12-22T15:01:23.045123456Z"),
Expand All @@ -76,9 +75,8 @@ func TestFormat(t *testing.T) {
useIncomingTimestamp: true,
expected: api.Entry{
Labels: model.LabelSet{
"jobname": "pubsub-test",
"resource_type": "gcs",
"promtail_instance": model.LabelValue(instanceID.String()),
"jobname": "pubsub-test",
"resource_type": "gcs",
},
Entry: logproto.Entry{
Timestamp: mustTime(t, "2020-12-22T15:01:23.045123456Z"),
Expand All @@ -96,9 +94,8 @@ func TestFormat(t *testing.T) {
},
expected: api.Entry{
Labels: model.LabelSet{
"jobname": "pubsub-test",
"resource_type": "gcs",
"promtail_instance": model.LabelValue(instanceID.String()),
"jobname": "pubsub-test",
"resource_type": "gcs",
},
Entry: logproto.Entry{
Timestamp: time.Now(),
Expand Down
4 changes: 0 additions & 4 deletions docs/sources/clients/promtail/scraping.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ It also support `relabeling` and `pipeline` stages just like other targets.

When Promtail receives GCP logs the labels that are set on the GCP resources are available as internal labels. Like in the example above, the `__project_id` label from a GCP resource was transformed into a label called `project` through `relabel_configs`. See [Relabeling](#relabeling) for more information.

Log entries scraped by `gcplog` will add an additional label called `promtail_instance`. This label uniquely identifies each Promtail instance trying to scrape gcplog (from a single `subscription_id`).
We need this unique identifier to avoid out-of-order errors from Loki servers when Loki is not configured to [accept out-of-order writes](../../../configuration/#accept-out-of-order-writes).
If two Promtail instances rewrite the timestamp of log entries (with same labelset) at the same time, the log entries may reach Loki servers at different times. This can cause Loki servers to reject the out-of-order log entry.

## Syslog Receiver

Promtail supports receiving [IETF Syslog (RFC5424)](https://tools.ietf.org/html/rfc5424)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ require (
github.com/go-logfmt/logfmt v0.5.1
github.com/go-redis/redis/v8 v8.11.4
github.com/gocql/gocql v0.0.0-20200526081602-cd04bd7f22a7
github.com/gofrs/uuid v4.0.0+incompatible
github.com/gogo/protobuf v1.3.2 // remember to update loki-build-image/Dockerfile too
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.4
Expand Down Expand Up @@ -162,6 +161,7 @@ require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-zookeeper/zk v1.0.2 // indirect
github.com/gofrs/flock v0.7.1 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/gogo/googleapis v1.4.0 // indirect
github.com/gogo/status v1.1.0 // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
Expand Down