...
1// Code created by gotmpl. DO NOT MODIFY.
2// source: internal/shared/otlp/otlpmetric/otest/client_test.go.tmpl
3
4// Copyright The OpenTelemetry Authors
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18package otest
19
20import (
21 "context"
22 "testing"
23
24 "go.opentelemetry.io/otel"
25 "{{ .internalImportPath }}"
26 "go.opentelemetry.io/otel/sdk/metric"
27 "go.opentelemetry.io/otel/sdk/metric/metricdata"
28 cpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
29 mpb "go.opentelemetry.io/proto/otlp/metrics/v1"
30)
31
32type client struct {
33 rCh <-chan ExportResult
34 storage *Storage
35}
36
37func (c *client) Temporality(k metric.InstrumentKind) metricdata.Temporality {
38 return metric.DefaultTemporalitySelector(k)
39}
40
41func (c *client) Aggregation(k metric.InstrumentKind) metric.Aggregation {
42 return metric.DefaultAggregationSelector(k)
43}
44
45func (c *client) Collect() *Storage {
46 return c.storage
47}
48
49func (c *client) UploadMetrics(ctx context.Context, rm *mpb.ResourceMetrics) error {
50 c.storage.Add(&cpb.ExportMetricsServiceRequest{
51 ResourceMetrics: []*mpb.ResourceMetrics{rm},
52 })
53 if c.rCh != nil {
54 r := <-c.rCh
55 if r.Response != nil && r.Response.GetPartialSuccess() != nil {
56 msg := r.Response.GetPartialSuccess().GetErrorMessage()
57 n := r.Response.GetPartialSuccess().GetRejectedDataPoints()
58 if msg != "" || n > 0 {
59 otel.Handle(internal.MetricPartialSuccessError(n, msg))
60 }
61 }
62 return r.Err
63 }
64 return ctx.Err()
65}
66
67func (c *client) ForceFlush(ctx context.Context) error { return ctx.Err() }
68func (c *client) Shutdown(ctx context.Context) error { return ctx.Err() }
69
70func TestClientTests(t *testing.T) {
71 factory := func(rCh <-chan ExportResult) (Client, Collector) {
72 c := &client{rCh: rCh, storage: NewStorage()}
73 return c, c
74 }
75
76 t.Run("Integration", RunClientTests(factory))
77}
View as plain text