| 1 |
// Code generated by gotmpl. DO NOT MODIFY. |
| 2 |
// source: internal/shared/otlp/otlpmetric/otest/client_test.go.tmpl |
| 3 |
|
| 4 |
// Copyright The OpenTelemetry Authors |
| 5 |
// SPDX-License-Identifier: Apache-2.0 |
| 6 |
|
| 7 |
package otest |
| 8 |
|
| 9 |
import ( |
| 10 |
"context" |
| 11 |
"errors" |
| 12 |
"testing" |
| 13 |
|
| 14 |
"{{ .internalImportPath }}" |
| 15 |
"go.opentelemetry.io/otel/sdk/metric" |
| 16 |
"go.opentelemetry.io/otel/sdk/metric/metricdata" |
| 17 |
cpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1" |
| 18 |
mpb "go.opentelemetry.io/proto/otlp/metrics/v1" |
| 19 |
) |
| 20 |
|
| 21 |
type client struct { |
| 22 |
rCh <-chan ExportResult |
| 23 |
storage *Storage |
| 24 |
} |
| 25 |
|
| 26 |
func (c *client) Temporality(k metric.InstrumentKind) metricdata.Temporality { |
| 27 |
return metric.DefaultTemporalitySelector(k) |
| 28 |
} |
| 29 |
|
| 30 |
func (c *client) Aggregation(k metric.InstrumentKind) metric.Aggregation { |
| 31 |
return metric.DefaultAggregationSelector(k) |
| 32 |
} |
| 33 |
|
| 34 |
func (c *client) Collect() *Storage { |
| 35 |
return c.storage |
| 36 |
} |
| 37 |
|
| 38 |
func (c *client) UploadMetrics(ctx context.Context, rm *mpb.ResourceMetrics) error { |
| 39 |
c.storage.Add(&cpb.ExportMetricsServiceRequest{ |
| 40 |
ResourceMetrics: []*mpb.ResourceMetrics{rm}, |
| 41 |
}) |
| 42 |
if c.rCh != nil { |
| 43 |
r := <-c.rCh |
| 44 |
err := r.Err |
| 45 |
if r.Response != nil && r.Response.GetPartialSuccess() != nil { |
| 46 |
msg := r.Response.GetPartialSuccess().GetErrorMessage() |
| 47 |
n := r.Response.GetPartialSuccess().GetRejectedDataPoints() |
| 48 |
if msg != "" || n > 0 { |
| 49 |
err = errors.Join(err, internal.MetricPartialSuccessError(n, msg)) |
| 50 |
} |
| 51 |
} |
| 52 |
return err |
| 53 |
} |
| 54 |
return ctx.Err() |
| 55 |
} |
| 56 |
|
| 57 |
func (c *client) ForceFlush(ctx context.Context) error { return ctx.Err() } |
| 58 |
func (c *client) Shutdown(ctx context.Context) error { return ctx.Err() } |
| 59 |
|
| 60 |
func TestClientTests(t *testing.T) { |
| 61 |
factory := func(rCh <-chan ExportResult) (Client, Collector) { |
| 62 |
c := &client{rCh: rCh, storage: NewStorage()} |
| 63 |
return c, c |
| 64 |
} |
| 65 |
|
| 66 |
t.Run("Integration", RunClientTests(factory)) |
| 67 |
} |