Skip to content

Commit

Permalink
Merge branch 'main' into balance-metrics-by-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
SHaaD94 committed Mar 24, 2024
2 parents 65bcb4a + 420bdba commit e536f98
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .chloggen/carbonreceiver-error-closed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: carbonreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Do not report fatal error when closed normally

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [31913]

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
27 changes: 27 additions & 0 deletions .chloggen/fix-telemetrygen-log-attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: cmd/telemetrygen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixed key mapping for logs telemetry attributes.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [31309]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
4 changes: 2 additions & 2 deletions cmd/telemetrygen/internal/logs/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (w worker) simulateLogs(res *resource.Resource, exporter exporter, telemetr
lattrs := log.Attributes()
lattrs.PutStr("app", "server")

for i, key := range telemetryAttributes {
lattrs.PutStr(key.Value.AsString(), telemetryAttributes[i].Value.AsString())
for i, attr := range telemetryAttributes {
lattrs.PutStr(string(attr.Key), telemetryAttributes[i].Value.AsString())
}

if err := exporter.export(logs); err != nil {
Expand Down
7 changes: 7 additions & 0 deletions cmd/telemetrygen/internal/logs/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ func TestLogsWithOneTelemetryAttributes(t *testing.T) {
for i := 0; i < rlogs.Len(); i++ {
attrs := rlogs.At(i).ScopeLogs().At(0).LogRecords().At(0).Attributes()
assert.Equal(t, 2, attrs.Len(), "shouldn't have less than 2 attributes")

val, ok := attrs.Get(telemetryAttrKeyOne)
assert.Truef(t, ok, "there should be an attribute with key %s", telemetryAttrKeyOne)
if ok {
assert.EqualValues(t, val.AsString(), telemetryAttrValueOne)
}

}
}
}
Expand Down
2 changes: 2 additions & 0 deletions receiver/carbonreceiver/internal/transport/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Server interface {
// ListenAndServe is a blocking call that starts to listen for client messages
// on the specific transport, and prepares the message to be processed by
// the Parser and passed to the next consumer.
//
// Returns net.ErrClosed when closed.
ListenAndServe(
p protocol.Parser,
mc consumer.Metrics,
Expand Down
3 changes: 2 additions & 1 deletion receiver/carbonreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"net"
"strings"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -96,7 +97,7 @@ func (r *carbonReceiver) Start(_ context.Context, _ component.Host) error {
}
r.server = server
go func() {
if err := r.server.ListenAndServe(r.parser, r.nextConsumer, r.reporter); err != nil {
if err := r.server.ListenAndServe(r.parser, r.nextConsumer, r.reporter); err != nil && !errors.Is(err, net.ErrClosed) {
r.settings.ReportStatus(component.NewFatalErrorEvent(err))
}
}()
Expand Down
4 changes: 4 additions & 0 deletions receiver/carbonreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/consumer"
Expand Down Expand Up @@ -192,6 +193,9 @@ func Test_carbonreceiver_EndToEnd(t *testing.T) {
rt := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(recorder))
cs := receivertest.NewNopCreateSettings()
cs.TracerProvider = rt
cs.ReportStatus = func(event *component.StatusEvent) {
assert.NoError(t, event.Err())
}
rcv, err := newMetricsReceiver(cs, *cfg, sink)
require.NoError(t, err)
r := rcv.(*carbonReceiver)
Expand Down
1 change: 1 addition & 0 deletions receiver/k8seventsreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ func TestCreateReceiver(t *testing.T) {
require.NoError(t, err)
err = r.Start(context.Background(), componenttest.NewNopHost())
assert.NoError(t, err)
require.NoError(t, r.Shutdown(context.Background()))
}
1 change: 1 addition & 0 deletions receiver/k8seventsreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
go.opentelemetry.io/collector/semconv v0.96.1-0.20240315172937-3b5aee0c7a16
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
k8s.io/api v0.29.3
k8s.io/apimachinery v0.29.3
Expand Down
14 changes: 14 additions & 0 deletions receiver/k8seventsreceiver/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package k8seventsreceiver

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}

0 comments on commit e536f98

Please sign in to comment.