Skip to content

Commit

Permalink
Promtail: no need for GCP promtail_instance label now that loki suppo…
Browse files Browse the repository at this point in the history
…rts out-of-order writes (#4556)

Closes #4474
  • Loading branch information
james-callahan authored Nov 3, 2021
1 parent 62ee399 commit a92541b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 31 deletions.
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

0 comments on commit a92541b

Please sign in to comment.