Skip to content

Commit

Permalink
lokiexporter: Remove dependency on https://github.com/grafana/loki, d…
Browse files Browse the repository at this point in the history
…ue to incompatible dep issues (#2385)

* copied logproto files from https://github.com/grafana/loki/blob/master/pkg/logproto

Signed-off-by: Granville Schmidt <1246157+gramidt@users.noreply.github.com>

* updated imports to use local copy of logproto

Signed-off-by: Granville Schmidt <1246157+gramidt@users.noreply.github.com>

* fixed import formatting

Signed-off-by: Granville Schmidt <1246157+gramidt@users.noreply.github.com>

* added otel copyright to logproto files due to licensecheck

Signed-off-by: Granville Schmidt <1246157+gramidt@users.noreply.github.com>
  • Loading branch information
gramidt authored Feb 20, 2021
1 parent acda163 commit e43c235
Show file tree
Hide file tree
Showing 11 changed files with 8,942 additions and 477 deletions.
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).

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

0 comments on commit e43c235

Please sign in to comment.