Skip to content

Commit 9e4d50f

Browse files
authored
remove opencensus from carbonreceiver and wavefrontreceiver (open-telemetry#23248)
Update carbonreceiver and wavefrontreceiver to use pdata directly instead of OpenCensus
1 parent e0249e0 commit 9e4d50f

17 files changed

+476
-567
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use this changelog template to create an entry for release notes.
2+
# If your change doesn't affect end users, such as a test fix or a tooling change,
3+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
4+
5+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
6+
change_type: enhancement
7+
8+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
9+
component: carbonreceiver, wavefrontreceiver
10+
11+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
12+
note: Remove use of opencensus model in carbonreceiver and wavefrontreceiver
13+
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [20759, 20761]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext:

receiver/carbonreceiver/go.mod

+2-14
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbon
33
go 1.19
44

55
require (
6-
github.com/census-instrumentation/opencensus-proto v0.4.1
76
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.79.0
8-
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.79.0
97
github.com/stretchr/testify v1.8.4
108
go.opencensus.io v0.24.0
119
go.opentelemetry.io/collector v0.79.0
1210
go.opentelemetry.io/collector/component v0.79.0
1311
go.opentelemetry.io/collector/confmap v0.79.0
1412
go.opentelemetry.io/collector/consumer v0.79.0
13+
go.opentelemetry.io/collector/pdata v1.0.0-rcv0012
1514
go.opentelemetry.io/collector/receiver v0.79.0
1615
go.uber.org/zap v1.24.0
17-
google.golang.org/protobuf v1.30.0
1816
)
1917

2018
require (
@@ -37,7 +35,6 @@ require (
3735
github.com/mitchellh/reflectwalk v1.0.2 // indirect
3836
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3937
github.com/modern-go/reflect2 v1.0.2 // indirect
40-
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.79.0 // indirect
4138
github.com/pmezard/go-difflib v1.0.0 // indirect
4239
github.com/prometheus/client_golang v1.15.1 // indirect
4340
github.com/prometheus/client_model v0.4.0 // indirect
@@ -46,8 +43,6 @@ require (
4643
github.com/prometheus/statsd_exporter v0.22.7 // indirect
4744
go.opentelemetry.io/collector/exporter v0.79.0 // indirect
4845
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0012 // indirect
49-
go.opentelemetry.io/collector/pdata v1.0.0-rcv0012 // indirect
50-
go.opentelemetry.io/collector/semconv v0.79.0 // indirect
5146
go.opentelemetry.io/otel v1.16.0 // indirect
5247
go.opentelemetry.io/otel/exporters/prometheus v0.39.0 // indirect
5348
go.opentelemetry.io/otel/metric v1.16.0 // indirect
@@ -61,22 +56,15 @@ require (
6156
golang.org/x/text v0.9.0 // indirect
6257
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
6358
google.golang.org/grpc v1.55.0 // indirect
59+
google.golang.org/protobuf v1.30.0 // indirect
6460
gopkg.in/yaml.v2 v2.4.0 // indirect
6561
gopkg.in/yaml.v3 v3.0.1 // indirect
6662
)
6763

68-
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus => ../../pkg/translator/opencensus
69-
7064
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common
7165

72-
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../internal/coreinternal
73-
7466
retract (
7567
v0.76.2
7668
v0.76.1
7769
v0.65.0
7870
)
79-
80-
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest
81-
82-
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../pkg/pdatautil

receiver/carbonreceiver/go.sum

-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/carbonreceiver/protocol/parser.go

+2-36
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
package protocol // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/protocol"
55

66
import (
7-
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
8-
"google.golang.org/protobuf/types/known/timestamppb"
7+
"go.opentelemetry.io/collector/pdata/pmetric"
98
)
109

1110
// Parser abstracts the type of parsing being done by the receiver.
@@ -24,38 +23,5 @@ type Parser interface {
2423
//
2524
// The <metric_timestamp> is the Unix time text of when the measurement was
2625
// made.
27-
Parse(line string) (*metricspb.Metric, error)
28-
}
29-
30-
// Below a few helper functions useful to different parsers.
31-
func buildMetricForSinglePoint(
32-
metricName string,
33-
metricType metricspb.MetricDescriptor_Type,
34-
labelKeys []*metricspb.LabelKey,
35-
labelValues []*metricspb.LabelValue,
36-
point *metricspb.Point,
37-
) *metricspb.Metric {
38-
return &metricspb.Metric{
39-
MetricDescriptor: &metricspb.MetricDescriptor{
40-
Name: metricName,
41-
Type: metricType,
42-
LabelKeys: labelKeys,
43-
},
44-
Timeseries: []*metricspb.TimeSeries{
45-
{
46-
// TODO: StartTimestamp can be set if each cumulative time series are
47-
// tracked but right now it is not clear if it brings benefits.
48-
// Perhaps as an option so cost is "pay for play".
49-
LabelValues: labelValues,
50-
Points: []*metricspb.Point{point},
51-
},
52-
},
53-
}
54-
}
55-
56-
func convertUnixSec(sec int64) *timestamppb.Timestamp {
57-
ts := &timestamppb.Timestamp{
58-
Seconds: sec,
59-
}
60-
return ts
26+
Parse(line string) (pmetric.Metric, error)
6127
}

receiver/carbonreceiver/protocol/path_parser_helper.go

+32-37
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import (
88
"fmt"
99
"strconv"
1010
"strings"
11+
"time"
1112

12-
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
13+
"go.opentelemetry.io/collector/pdata/pcommon"
14+
"go.opentelemetry.io/collector/pdata/pmetric"
1315
)
1416

1517
// PathParser implements the code needed to handle only the <metric_path> part of
@@ -35,10 +37,8 @@ type PathParser interface {
3537
type ParsedPath struct {
3638
// MetricName extracted/generated by the parser.
3739
MetricName string
38-
// LabelKeys extracted/generated by the parser.
39-
LabelKeys []*metricspb.LabelKey
40-
// LabelValues extracted/generated by the parser.
41-
LabelValues []*metricspb.LabelValue
40+
// Attributes extracted/generated by the parser.
41+
Attributes pcommon.Map
4242
// MetricType instructs the helper to generate the metric as the specified
4343
// TargetMetricType.
4444
MetricType TargetMetricType
@@ -88,10 +88,10 @@ func NewParser(pathParser PathParser) (Parser, error) {
8888
//
8989
// The <metric_timestamp> is the Unix time text of when the measurement was
9090
// made.
91-
func (pph *PathParserHelper) Parse(line string) (*metricspb.Metric, error) {
91+
func (pph *PathParserHelper) Parse(line string) (pmetric.Metric, error) {
9292
parts := strings.SplitN(line, " ", 4)
9393
if len(parts) != 3 {
94-
return nil, fmt.Errorf("invalid carbon metric [%s]", line)
94+
return pmetric.Metric{}, fmt.Errorf("invalid carbon metric [%s]", line)
9595
}
9696

9797
path := parts[0]
@@ -101,44 +101,39 @@ func (pph *PathParserHelper) Parse(line string) (*metricspb.Metric, error) {
101101
parsedPath := ParsedPath{}
102102
err := pph.pathParser.ParsePath(path, &parsedPath)
103103
if err != nil {
104-
return nil, fmt.Errorf("invalid carbon metric [%s]: %w", line, err)
104+
return pmetric.Metric{}, fmt.Errorf("invalid carbon metric [%s]: %w", line, err)
105105
}
106106

107107
unixTime, err := strconv.ParseInt(timestampStr, 10, 64)
108108
if err != nil {
109-
return nil, fmt.Errorf("invalid carbon metric time [%s]: %w", line, err)
109+
return pmetric.Metric{}, fmt.Errorf("invalid carbon metric time [%s]: %w", line, err)
110110
}
111111

112-
var metricType metricspb.MetricDescriptor_Type
113-
point := metricspb.Point{
114-
Timestamp: convertUnixSec(unixTime),
115-
}
116-
intVal, err := strconv.ParseInt(valueStr, 10, 64)
117-
if err == nil {
118-
if parsedPath.MetricType == CumulativeMetricType {
119-
metricType = metricspb.MetricDescriptor_CUMULATIVE_INT64
120-
} else {
121-
metricType = metricspb.MetricDescriptor_GAUGE_INT64
122-
}
123-
point.Value = &metricspb.Point_Int64Value{Int64Value: intVal}
124-
} else {
125-
dblVal, err := strconv.ParseFloat(valueStr, 64)
112+
intVal, errIsFloat := strconv.ParseInt(valueStr, 10, 64)
113+
var dblVal float64
114+
if errIsFloat != nil {
115+
dblVal, err = strconv.ParseFloat(valueStr, 64)
126116
if err != nil {
127-
return nil, fmt.Errorf("invalid carbon metric value [%s]: %w", line, err)
128-
}
129-
if parsedPath.MetricType == CumulativeMetricType {
130-
metricType = metricspb.MetricDescriptor_CUMULATIVE_DOUBLE
131-
} else {
132-
metricType = metricspb.MetricDescriptor_GAUGE_DOUBLE
117+
return pmetric.Metric{}, fmt.Errorf("invalid carbon metric value [%s]: %w", line, err)
133118
}
134-
point.Value = &metricspb.Point_DoubleValue{DoubleValue: dblVal}
135119
}
136120

137-
metric := buildMetricForSinglePoint(
138-
parsedPath.MetricName,
139-
metricType,
140-
parsedPath.LabelKeys,
141-
parsedPath.LabelValues,
142-
&point)
143-
return metric, nil
121+
m := pmetric.NewMetric()
122+
m.SetName(parsedPath.MetricName)
123+
var dp pmetric.NumberDataPoint
124+
if parsedPath.MetricType == CumulativeMetricType {
125+
sum := m.SetEmptySum()
126+
sum.SetIsMonotonic(true)
127+
dp = sum.DataPoints().AppendEmpty()
128+
} else {
129+
dp = m.SetEmptyGauge().DataPoints().AppendEmpty()
130+
}
131+
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(unixTime, 0)))
132+
if errIsFloat != nil {
133+
dp.SetDoubleValue(dblVal)
134+
} else {
135+
dp.SetIntValue(intVal)
136+
}
137+
parsedPath.Attributes.CopyTo(dp.Attributes())
138+
return m, nil
144139
}

receiver/carbonreceiver/protocol/plaintext_parser.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"strings"
99

10-
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
10+
"go.opentelemetry.io/collector/pdata/pcommon"
1111
)
1212

1313
// PlaintextConfig holds the configuration for the plaintext parser.
@@ -44,6 +44,7 @@ func (p *PlaintextPathParser) ParsePath(path string, parsedPath *ParsedPath) err
4444
}
4545

4646
parsedPath.MetricName = parts[0]
47+
parsedPath.Attributes = pcommon.NewMap()
4748
if len(parts) == 1 {
4849
// No tags, no more work here.
4950
return nil
@@ -55,26 +56,17 @@ func (p *PlaintextPathParser) ParsePath(path string, parsedPath *ParsedPath) err
5556
}
5657

5758
tags := strings.Split(parts[1], ";")
58-
keys := make([]*metricspb.LabelKey, 0, len(tags))
59-
values := make([]*metricspb.LabelValue, 0, len(tags))
6059
for _, tag := range tags {
6160
idx := strings.IndexByte(tag, '=')
6261
if idx < 1 {
6362
return fmt.Errorf("cannot parse metric path [%s]: incorrect key value separator for [%s]", path, tag)
6463
}
6564

6665
key := tag[:idx]
67-
keys = append(keys, &metricspb.LabelKey{Key: key})
68-
6966
value := tag[idx+1:] // If value is empty, ie.: tag == "k=", this will return "".
70-
values = append(values, &metricspb.LabelValue{
71-
Value: value,
72-
HasValue: true,
73-
})
67+
parsedPath.Attributes.PutStr(key, value)
7468
}
7569

76-
parsedPath.LabelKeys = keys
77-
parsedPath.LabelValues = values
7870
return nil
7971
}
8072

0 commit comments

Comments
 (0)