-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add back the otlpmetric transforms (#3065)
* Add otlpmetric transforms * Split aggregation transforms to own file * Rename Iterator to AttrIter * Update pkg docs These are internal docs use developer based language. * Document all exported funcs * Unify metricdata type transforms into one file * Rename metrics.go to metricdata.go * Copy back attribute tests * Copy back in Iterator test * Refactor attribute tests * Add tests for metricdata transforms * Add multiErr support for digestible transform errs * Test transform errors * go mod tidy * Use key field * goimported * gofmt-ed * Fix error documentation * go mod tidy
- Loading branch information
Showing
10 changed files
with
1,596 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module go.opentelemetry.io/otel/exporters/otlp/otlpmetric | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/stretchr/testify v1.7.1 | ||
go.opentelemetry.io/otel v1.9.0 | ||
go.opentelemetry.io/otel/metric v0.0.0-00010101000000-000000000000 | ||
go.opentelemetry.io/otel/sdk v0.0.0-00010101000000-000000000000 | ||
go.opentelemetry.io/otel/sdk/metric v0.0.0-00010101000000-000000000000 | ||
go.opentelemetry.io/proto/otlp v0.18.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.0 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.9.0 // indirect | ||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect | ||
google.golang.org/protobuf v1.27.1 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect | ||
) | ||
|
||
replace go.opentelemetry.io/otel/metric => ../../../metric | ||
|
||
replace go.opentelemetry.io/otel => ../../.. | ||
|
||
replace go.opentelemetry.io/otel/sdk/metric => ../../../sdk/metric | ||
|
||
replace go.opentelemetry.io/otel/trace => ../../../trace | ||
|
||
replace go.opentelemetry.io/otel/sdk => ../../../sdk |
Large diffs are not rendered by default.
Oops, something went wrong.
155 changes: 155 additions & 0 deletions
155
exporters/otlp/otlpmetric/internal/transform/attribute.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// 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. | ||
|
||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package transform // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/transform" | ||
|
||
import ( | ||
"go.opentelemetry.io/otel/attribute" | ||
cpb "go.opentelemetry.io/proto/otlp/common/v1" | ||
) | ||
|
||
// AttrIter transforms an attribute iterator into OTLP key-values. | ||
func AttrIter(iter attribute.Iterator) []*cpb.KeyValue { | ||
l := iter.Len() | ||
if l == 0 { | ||
return nil | ||
} | ||
|
||
out := make([]*cpb.KeyValue, 0, l) | ||
for iter.Next() { | ||
out = append(out, KeyValue(iter.Attribute())) | ||
} | ||
return out | ||
} | ||
|
||
// KeyValues transforms a slice of attribute KeyValues into OTLP key-values. | ||
func KeyValues(attrs []attribute.KeyValue) []*cpb.KeyValue { | ||
if len(attrs) == 0 { | ||
return nil | ||
} | ||
|
||
out := make([]*cpb.KeyValue, 0, len(attrs)) | ||
for _, kv := range attrs { | ||
out = append(out, KeyValue(kv)) | ||
} | ||
return out | ||
} | ||
|
||
// KeyValue transforms an attribute KeyValue into an OTLP key-value. | ||
func KeyValue(kv attribute.KeyValue) *cpb.KeyValue { | ||
return &cpb.KeyValue{Key: string(kv.Key), Value: Value(kv.Value)} | ||
} | ||
|
||
// Value transforms an attribute Value into an OTLP AnyValue. | ||
func Value(v attribute.Value) *cpb.AnyValue { | ||
av := new(cpb.AnyValue) | ||
switch v.Type() { | ||
case attribute.BOOL: | ||
av.Value = &cpb.AnyValue_BoolValue{ | ||
BoolValue: v.AsBool(), | ||
} | ||
case attribute.BOOLSLICE: | ||
av.Value = &cpb.AnyValue_ArrayValue{ | ||
ArrayValue: &cpb.ArrayValue{ | ||
Values: boolSliceValues(v.AsBoolSlice()), | ||
}, | ||
} | ||
case attribute.INT64: | ||
av.Value = &cpb.AnyValue_IntValue{ | ||
IntValue: v.AsInt64(), | ||
} | ||
case attribute.INT64SLICE: | ||
av.Value = &cpb.AnyValue_ArrayValue{ | ||
ArrayValue: &cpb.ArrayValue{ | ||
Values: int64SliceValues(v.AsInt64Slice()), | ||
}, | ||
} | ||
case attribute.FLOAT64: | ||
av.Value = &cpb.AnyValue_DoubleValue{ | ||
DoubleValue: v.AsFloat64(), | ||
} | ||
case attribute.FLOAT64SLICE: | ||
av.Value = &cpb.AnyValue_ArrayValue{ | ||
ArrayValue: &cpb.ArrayValue{ | ||
Values: float64SliceValues(v.AsFloat64Slice()), | ||
}, | ||
} | ||
case attribute.STRING: | ||
av.Value = &cpb.AnyValue_StringValue{ | ||
StringValue: v.AsString(), | ||
} | ||
case attribute.STRINGSLICE: | ||
av.Value = &cpb.AnyValue_ArrayValue{ | ||
ArrayValue: &cpb.ArrayValue{ | ||
Values: stringSliceValues(v.AsStringSlice()), | ||
}, | ||
} | ||
default: | ||
av.Value = &cpb.AnyValue_StringValue{ | ||
StringValue: "INVALID", | ||
} | ||
} | ||
return av | ||
} | ||
|
||
func boolSliceValues(vals []bool) []*cpb.AnyValue { | ||
converted := make([]*cpb.AnyValue, len(vals)) | ||
for i, v := range vals { | ||
converted[i] = &cpb.AnyValue{ | ||
Value: &cpb.AnyValue_BoolValue{ | ||
BoolValue: v, | ||
}, | ||
} | ||
} | ||
return converted | ||
} | ||
|
||
func int64SliceValues(vals []int64) []*cpb.AnyValue { | ||
converted := make([]*cpb.AnyValue, len(vals)) | ||
for i, v := range vals { | ||
converted[i] = &cpb.AnyValue{ | ||
Value: &cpb.AnyValue_IntValue{ | ||
IntValue: v, | ||
}, | ||
} | ||
} | ||
return converted | ||
} | ||
|
||
func float64SliceValues(vals []float64) []*cpb.AnyValue { | ||
converted := make([]*cpb.AnyValue, len(vals)) | ||
for i, v := range vals { | ||
converted[i] = &cpb.AnyValue{ | ||
Value: &cpb.AnyValue_DoubleValue{ | ||
DoubleValue: v, | ||
}, | ||
} | ||
} | ||
return converted | ||
} | ||
|
||
func stringSliceValues(vals []string) []*cpb.AnyValue { | ||
converted := make([]*cpb.AnyValue, len(vals)) | ||
for i, v := range vals { | ||
converted[i] = &cpb.AnyValue{ | ||
Value: &cpb.AnyValue_StringValue{ | ||
StringValue: v, | ||
}, | ||
} | ||
} | ||
return converted | ||
} |
Oops, something went wrong.