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

Decouple otlp/otlpmetric/otlpmetricgrpc and otlp/otlpmetric/otlpmetrichttp from otlp/internal and otlp/otlpmetric/internal using gotmp #4403

Closed
wants to merge 13 commits into from
16 changes: 5 additions & 11 deletions exporters/otlp/otlpmetric/internal/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package internal provides common utilities for all otlpmetric exporters.
//
// Deprecated: package internal exists for historical compatibility, it should
// not be used.
package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal"

import (
"context"
"fmt"
"sync"

"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/transform"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/transform" // nolint: staticcheck // Atomic deprecation.
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
mpb "go.opentelemetry.io/proto/otlp/metrics/v1"
)

// Exporter exports metrics data as OTLP.
//
// Deprecated: Exporter exists for historical compatibility, it should not be
// used. Do not remove Exporter unless the whole
// "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal" module is
// removed.
type Exporter struct {
// Ensure synchronous access to the client across all functionality.
clientMu sync.Mutex
Expand Down Expand Up @@ -101,11 +100,6 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
// New return an Exporter that uses client to transmits the OTLP data it
// produces. The client is assumed to be fully started and able to communicate
// with its OTLP receiving endpoint.
//
// Deprecated: New exists for historical compatibility, it should not be used.
// Do not remove New unless the whole
// "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal" module is
// removed.
func New(client Client) *Exporter {
return &Exporter{client: client}
}
Expand Down
7 changes: 6 additions & 1 deletion exporters/otlp/otlpmetric/internal/oconf/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package oconf provides common metric configuration types and functionality
// for all otlpmetric exporters.
//
// Deprecated: package oconf exists for historical compatibility, it should not
// be used.
package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/oconf"

import (
Expand All @@ -27,7 +32,7 @@ import (

"go.opentelemetry.io/otel/exporters/otlp/internal"
"go.opentelemetry.io/otel/exporters/otlp/internal/retry"
ominternal "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal"
ominternal "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal" // nolint: staticcheck // Atomic deprecation.
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
Expand Down
7 changes: 6 additions & 1 deletion exporters/otlp/otlpmetric/internal/otest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package otest provides common testing utilities for all otlpmetric
// exporters.
//
// Deprecated: package otest exists for historical compatibility, it should not
// be used.
package otest // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/otest"

import (
Expand All @@ -26,7 +31,7 @@ import (
"google.golang.org/protobuf/proto"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal" // nolint: staticcheck // Atomic deprecation.
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
collpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
cpb "go.opentelemetry.io/proto/otlp/common/v1"
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpmetric/internal/otest/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/internal"
ominternal "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal"
ominternal "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal" // nolint: staticcheck // Atomic deprecation.
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpmetric/internal/otest/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"

"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/oconf"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/oconf" // nolint: staticcheck // Atomic deprecation.
collpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
mpb "go.opentelemetry.io/proto/otlp/metrics/v1"
)
Expand Down
3 changes: 3 additions & 0 deletions exporters/otlp/otlpmetric/internal/transform/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@

// Package transform provides transformation functionality from the
// sdk/metric/metricdata data-types into OTLP data-types.
//
// Deprecated: package transform exists for historical compatibility, it should
// not be used.
package transform // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/transform"
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Code created by gotmpl. DO NOT MODIFY.
// source: internal/shared/otlp/otlpmetric/oconf/envconfig_test.go.tmpl

// 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 oconf

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

func TestWithEnvTemporalityPreference(t *testing.T) {
origReader := DefaultEnvOptionsReader.GetEnv
tests := []struct {
name string
envValue string
want map[metric.InstrumentKind]metricdata.Temporality
}{
{
name: "default do not set the selector",
envValue: "",
},
{
name: "non-normative do not set the selector",
envValue: "non-normative",
},
{
name: "cumulative",
envValue: "cumulative",
want: map[metric.InstrumentKind]metricdata.Temporality{
metric.InstrumentKindCounter: metricdata.CumulativeTemporality,
metric.InstrumentKindHistogram: metricdata.CumulativeTemporality,
metric.InstrumentKindUpDownCounter: metricdata.CumulativeTemporality,
metric.InstrumentKindObservableCounter: metricdata.CumulativeTemporality,
metric.InstrumentKindObservableUpDownCounter: metricdata.CumulativeTemporality,
metric.InstrumentKindObservableGauge: metricdata.CumulativeTemporality,
},
},
{
name: "delta",
envValue: "delta",
want: map[metric.InstrumentKind]metricdata.Temporality{
metric.InstrumentKindCounter: metricdata.DeltaTemporality,
metric.InstrumentKindHistogram: metricdata.DeltaTemporality,
metric.InstrumentKindUpDownCounter: metricdata.CumulativeTemporality,
metric.InstrumentKindObservableCounter: metricdata.DeltaTemporality,
metric.InstrumentKindObservableUpDownCounter: metricdata.CumulativeTemporality,
metric.InstrumentKindObservableGauge: metricdata.CumulativeTemporality,
},
},
{
name: "lowmemory",
envValue: "lowmemory",
want: map[metric.InstrumentKind]metricdata.Temporality{
metric.InstrumentKindCounter: metricdata.DeltaTemporality,
metric.InstrumentKindHistogram: metricdata.DeltaTemporality,
metric.InstrumentKindUpDownCounter: metricdata.CumulativeTemporality,
metric.InstrumentKindObservableCounter: metricdata.CumulativeTemporality,
metric.InstrumentKindObservableUpDownCounter: metricdata.CumulativeTemporality,
metric.InstrumentKindObservableGauge: metricdata.CumulativeTemporality,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
DefaultEnvOptionsReader.GetEnv = func(key string) string {
if key == "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE" {
return tt.envValue
}
return origReader(key)
}
cfg := Config{}
cfg = ApplyGRPCEnvConfigs(cfg)

if tt.want == nil {
// There is no function set, the SDK's default is used.
assert.Nil(t, cfg.Metrics.TemporalitySelector)
return
}

require.NotNil(t, cfg.Metrics.TemporalitySelector)
for ik, want := range tt.want {
assert.Equal(t, want, cfg.Metrics.TemporalitySelector(ik))
}
})
}
DefaultEnvOptionsReader.GetEnv = origReader
}
Loading