Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…y-collector-contrib into balance-metrics-by-resources
  • Loading branch information
Evgeniy Zuykin committed Feb 25, 2024
2 parents 1380a2a + 58f5fb7 commit b6b8177
Show file tree
Hide file tree
Showing 31 changed files with 203 additions and 171 deletions.
27 changes: 27 additions & 0 deletions .chloggen/lb-exporter-dummy-endpoint.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: loadbalancingexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixes a bug where the endpoint become required, despite not being used by the load balancing exporter.

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

# (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: [user]
2 changes: 1 addition & 1 deletion cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ require (
github.com/grobie/gomemcache v0.0.0-20230213081705-239240bbc445 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/haimrubinstein/go-syslog/v3 v3.0.0 // indirect
github.com/haimrubinstein/go-syslog/v3 v3.0.3 // indirect
github.com/hashicorp/consul/api v1.27.0 // indirect
github.com/hashicorp/cronexpr v1.1.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down
5 changes: 2 additions & 3 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion exporter/clickhouseexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Config struct {
Endpoint string `mapstructure:"endpoint"`
// Username is the authentication username.
Username string `mapstructure:"username"`
// Username is the authentication password.
// Password is the authentication password.
Password configopaque.String `mapstructure:"password"`
// Database is the database name to export.
Database string `mapstructure:"database"`
Expand Down
1 change: 1 addition & 0 deletions exporter/loadbalancingexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewFactory() exporter.Factory {
func createDefaultConfig() component.Config {
otlpFactory := otlpexporter.NewFactory()
otlpDefaultCfg := otlpFactory.CreateDefaultConfig().(*otlpexporter.Config)
otlpDefaultCfg.Endpoint = "placeholder"

return &Config{
Protocol: Protocol{
Expand Down
12 changes: 12 additions & 0 deletions exporter/loadbalancingexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ func TestLogExporterGetsCreatedWithValidConfiguration(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, exp)
}

func TestOTLPConfigIsValid(t *testing.T) {
// prepare
factory := NewFactory()
defaultCfg := factory.CreateDefaultConfig().(*Config)

// test
otlpCfg := defaultCfg.Protocol.OTLP

// verify
assert.NoError(t, otlpCfg.Validate())
}
2 changes: 1 addition & 1 deletion extension/jaegerremotesampling/internal/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *SamplingGRPCServer) Start(ctx context.Context, host component.Host) err
healthServer.SetServingStatus("jaeger.api_v2.SamplingManager", grpc_health_v1.HealthCheckResponse_SERVING)
grpc_health_v1.RegisterHealthServer(server, healthServer)

listener, err := s.settings.ToListenerContext(ctx)
listener, err := s.settings.NetAddr.Listen(ctx)
if err != nil {
return fmt.Errorf("failed to listen on gRPC port: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/sumologicextension/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// Config has the configuration for the sumologic extension.
type Config struct {
// squash ensures fields are correctly decoded in embedded struct.
confighttp.HTTPClientSettings `mapstructure:",squash"`
confighttp.ClientConfig `mapstructure:",squash"`

// Credentials contains Installation Token for Sumo Logic service.
// Please refer to https://help.sumologic.com/docs/manage/security/installation-tokens
Expand Down
22 changes: 22 additions & 0 deletions pkg/ottl/contexts/internal/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal"

import "fmt"

const (
DefaultErrorMessage = "segment %q from path %q is not a valid path nor a valid OTTL keyword for the %v context - review %v to see all valid paths"

ResourceContextRef = "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlresource"
InstrumentationScopeRef = "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlscope"
SpanRef = "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlspan"
SpanEventRef = "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlspanevent"
MetricRef = "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlmetric"
DataPointRef = "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottldatapoint"
LogRef = "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottllog"
)

func FormatDefaultErrorMessage(pathSegment, fullPath, context, ref string) error {
return fmt.Errorf(DefaultErrorMessage, pathSegment, fullPath, context, ref)
}
3 changes: 1 addition & 2 deletions pkg/ottl/contexts/internal/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internal // import "github.com/open-telemetry/opentelemetry-collector-co

import (
"context"
"fmt"

"go.opentelemetry.io/collector/pdata/pmetric"

Expand Down Expand Up @@ -48,7 +47,7 @@ func MetricPathGetSetter[K MetricContext](path ottl.Path[K]) (ottl.GetSetter[K],
case "data_points":
return accessDataPoints[K](), nil
default:
return nil, fmt.Errorf("invalid metric path expression %v", path)
return nil, FormatDefaultErrorMessage(path.Name(), path.String(), "Metric", MetricRef)
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/ottl/contexts/internal/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (p *TestPath[K]) Keys() []ottl.Key[K] {
return p.KeySlice
}

func (p *TestPath[K]) String() string {
return p.N
}

var _ ottl.Key[any] = &TestKey[any]{}

type TestKey[K any] struct {
Expand Down
3 changes: 1 addition & 2 deletions pkg/ottl/contexts/internal/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internal // import "github.com/open-telemetry/opentelemetry-collector-co

import (
"context"
"fmt"

"go.opentelemetry.io/collector/pdata/pcommon"

Expand All @@ -29,7 +28,7 @@ func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter
case "dropped_attributes_count":
return accessResourceDroppedAttributesCount[K](), nil
default:
return nil, fmt.Errorf("invalid resource path expression %v", path)
return nil, FormatDefaultErrorMessage(path.Name(), path.String(), "Resource", ResourceContextRef)
}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/ottl/contexts/internal/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internal // import "github.com/open-telemetry/opentelemetry-collector-co

import (
"context"
"fmt"

"go.opentelemetry.io/collector/pdata/pcommon"

Expand Down Expand Up @@ -34,7 +33,7 @@ func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.
case "dropped_attributes_count":
return accessInstrumentationScopeDroppedAttributesCount[K](), nil
default:
return nil, fmt.Errorf("invalid scope path expression %v", path)
return nil, FormatDefaultErrorMessage(path.Name(), path.String(), "Instrumentation Scope", InstrumentationScopeRef)
}
}

Expand Down
44 changes: 25 additions & 19 deletions pkg/ottl/contexts/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
)

const (
SpanContextName = "Span"
)

type SpanContext interface {
GetSpan() ptrace.Span
}
Expand All @@ -39,35 +43,38 @@ func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], err
}
switch path.Name() {
case "trace_id":
if path.Next() != nil {
if path.Next().Name() == "string" {
nextPath := path.Next()
if nextPath != nil {
if nextPath.Name() == "string" {
return accessStringTraceID[K](), nil
}
} else {
return accessTraceID[K](), nil
return nil, FormatDefaultErrorMessage(nextPath.Name(), nextPath.String(), SpanContextName, SpanRef)
}
return accessTraceID[K](), nil
case "span_id":
if path.Next() != nil {
if path.Next().Name() == "string" {
nextPath := path.Next()
if nextPath != nil {
if nextPath.Name() == "string" {
return accessStringSpanID[K](), nil
}
} else {
return accessSpanID[K](), nil
return nil, FormatDefaultErrorMessage(nextPath.Name(), nextPath.String(), SpanContextName, SpanRef)
}
return accessSpanID[K](), nil
case "trace_state":
mapKey := path.Keys()
if mapKey == nil {
return accessTraceState[K](), nil
}
return accessTraceStateKey[K](mapKey)
case "parent_span_id":
if path.Next() != nil {
if path.Next().Name() == "string" {
nextPath := path.Next()
if nextPath != nil {
if nextPath.Name() == "string" {
return accessStringParentSpanID[K](), nil
}
} else {
return accessParentSpanID[K](), nil
return nil, FormatDefaultErrorMessage(nextPath.Name(), nextPath.String(), SpanContextName, SpanRef)
}
return accessParentSpanID[K](), nil
case "name":
return accessSpanName[K](), nil
case "kind":
Expand All @@ -79,11 +86,10 @@ func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], err
case "deprecated_string":
return accessDeprecatedStringKind[K](), nil
default:
return nil, fmt.Errorf("invalid span path expression %v", nextPath.Name())
return nil, FormatDefaultErrorMessage(nextPath.Name(), nextPath.String(), SpanContextName, SpanRef)
}
} else {
return accessKind[K](), nil
}
return accessKind[K](), nil
case "start_time_unix_nano":
return accessStartTimeUnixNano[K](), nil
case "end_time_unix_nano":
Expand Down Expand Up @@ -117,13 +123,13 @@ func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], err
case "message":
return accessStatusMessage[K](), nil
default:
return nil, fmt.Errorf("invalid span path expression %v", nextPath.Name())
return nil, FormatDefaultErrorMessage(nextPath.Name(), nextPath.String(), SpanContextName, SpanRef)
}
} else {
return accessStatus[K](), nil
}
return accessStatus[K](), nil
default:
return nil, FormatDefaultErrorMessage(path.Name(), path.String(), SpanContextName, SpanRef)
}
return nil, fmt.Errorf("invalid span path expression %v", path)
}

func accessSpan[K SpanContext]() ottl.StandardGetSetter[K] {
Expand Down
17 changes: 10 additions & 7 deletions pkg/ottl/contexts/ottldatapoint/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal"
)

const (
contextName = "DataPoint"
)

var _ internal.ResourceContext = TransformContext{}
var _ internal.InstrumentationScopeContext = TransformContext{}

Expand Down Expand Up @@ -197,11 +201,10 @@ func (pep *pathExpressionParser) parsePath(path ottl.Path[TransformContext]) (ot
case "bucket_counts":
return accessPositiveBucketCounts(), nil
default:
return nil, fmt.Errorf("invalid span path expression %v", nextPath.Name())
return nil, internal.FormatDefaultErrorMessage(nextPath.Name(), path.String(), contextName, internal.DataPointRef)
}
} else {
return accessPositive(), nil
}
return accessPositive(), nil
case "negative":
nextPath := path.Next()
if nextPath != nil {
Expand All @@ -211,15 +214,15 @@ func (pep *pathExpressionParser) parsePath(path ottl.Path[TransformContext]) (ot
case "bucket_counts":
return accessNegativeBucketCounts(), nil
default:
return nil, fmt.Errorf("invalid span path expression %v", nextPath.Name())
return nil, internal.FormatDefaultErrorMessage(nextPath.Name(), path.String(), contextName, internal.DataPointRef)
}
} else {
return accessNegative(), nil
}
return accessNegative(), nil
case "quantile_values":
return accessQuantileValues(), nil
default:
return nil, internal.FormatDefaultErrorMessage(path.Name(), path.String(), contextName, internal.DataPointRef)
}
return nil, fmt.Errorf("invalid path expression %v", path)
}

func accessCache() ottl.StandardGetSetter[TransformContext] {
Expand Down
Loading

0 comments on commit b6b8177

Please sign in to comment.