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

lokiexporter: Remove dependency on https://github.com/grafana/loki, due to incompatible dep issues #2385

Merged
merged 4 commits into from
Feb 20, 2021
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
3 changes: 2 additions & 1 deletion exporter/lokiexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (

"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"github.com/grafana/loki/pkg/logproto"
"github.com/prometheus/common/model"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/consumer/pdata"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/lokiexporter/logproto"
)

type lokiExporter struct {
Expand Down
3 changes: 2 additions & 1 deletion exporter/lokiexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"time"

"github.com/golang/snappy"
"github.com/grafana/loki/pkg/logproto"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -35,6 +34,8 @@ import (
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/translator/conventions"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/lokiexporter/logproto"
)

const (
Expand Down
8 changes: 2 additions & 6 deletions exporter/lokiexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ go 1.14
require (
github.com/gogo/protobuf v1.3.2
github.com/golang/snappy v0.0.2
// The Loki repo doesn't currently follow the new go.mod semantics, since it's not typically used externally.
// To get this to work as is, we must import it using the following format: v0.0.0-timestamp-commithash
github.com/grafana/loki v0.0.0-20201223215703-1b79df3754f6
github.com/prometheus/common v0.15.0
github.com/prometheus/prometheus v1.8.2-0.20201105135750-00f16d1ac3a4
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/collector v0.20.1-0.20210218001603-48151d869607
go.uber.org/zap v1.16.0
google.golang.org/grpc v1.35.0
)

// Keeping these the same as Loki (https://github.com/grafana/loki/blob/master/go.mod) to avoid dependency issues.
replace k8s.io/client-go => k8s.io/client-go v0.19.2
475 changes: 6 additions & 469 deletions exporter/lokiexporter/go.sum

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions exporter/lokiexporter/logproto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Notice

This code was copied from https://github.com/grafana/loki/tree/master/pkg/logproto, due to incompatible dependency
issues when this exporter was added to the top level binary (top level go.mod replace, even with a specific version,
is not a good options due to other components' dependency requirements).

bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
https://github.com/grafana/loki-client-go was recently started, but is marked experimental and has not released a
version yet. Once this project has released a supported version, we should evaluate switching to it.

## License

Apache License 2.0

https://github.com/grafana/loki/blob/v2.1.0/LICENSE
37 changes: 37 additions & 0 deletions exporter/lokiexporter/logproto/extensions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package logproto

import "github.com/prometheus/prometheus/pkg/labels"

// Note, this is not very efficient and use should be minimized as it requires label construction on each comparison
type SeriesIdentifiers []SeriesIdentifier

func (ids SeriesIdentifiers) Len() int { return len(ids) }
func (ids SeriesIdentifiers) Swap(i, j int) { ids[i], ids[j] = ids[j], ids[i] }
func (ids SeriesIdentifiers) Less(i, j int) bool {
a, b := labels.FromMap(ids[i].Labels), labels.FromMap(ids[j].Labels)
return labels.Compare(a, b) <= 0
}

type Streams []Stream

func (xs Streams) Len() int { return len(xs) }
func (xs Streams) Swap(i, j int) { xs[i], xs[j] = xs[j], xs[i] }
func (xs Streams) Less(i, j int) bool { return xs[i].Labels <= xs[j].Labels }

func (s Series) Len() int { return len(s.Samples) }
func (s Series) Swap(i, j int) { s.Samples[i], s.Samples[j] = s.Samples[j], s.Samples[i] }
func (s Series) Less(i, j int) bool { return s.Samples[i].Timestamp < s.Samples[j].Timestamp }
Loading