Skip to content

Commit

Permalink
Removing go mod replace for collector
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev committed Nov 20, 2024
1 parent f0211d0 commit b51d740
Show file tree
Hide file tree
Showing 11 changed files with 580 additions and 268 deletions.
16 changes: 2 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ require (
go.opentelemetry.io/collector/consumer/consumertest v0.112.0
go.opentelemetry.io/collector/exporter v0.112.0
go.opentelemetry.io/collector/exporter/debugexporter v0.112.0
go.opentelemetry.io/collector/exporter/exportertest v0.112.0
go.opentelemetry.io/collector/exporter/otlpexporter v0.112.0
go.opentelemetry.io/collector/exporter/otlphttpexporter v0.112.0
go.opentelemetry.io/collector/extension v0.112.0
Expand All @@ -227,6 +228,7 @@ require (
go.opentelemetry.io/collector/processor v0.112.0
go.opentelemetry.io/collector/processor/batchprocessor v0.112.0
go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.112.0
go.opentelemetry.io/collector/processor/processortest v0.112.0
go.opentelemetry.io/collector/receiver v0.112.0
go.opentelemetry.io/collector/receiver/otlpreceiver v0.112.0
go.opentelemetry.io/collector/semconv v0.112.0
Expand Down Expand Up @@ -837,13 +839,11 @@ require (
go.opentelemetry.io/collector/consumer/consumererror/consumererrorprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/exporter/exporterhelper/exporterhelperprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/exporter/exportertest v0.112.0 // indirect
go.opentelemetry.io/collector/extension/experimental/storage v0.112.0 // indirect
go.opentelemetry.io/collector/extension/extensioncapabilities v0.112.0 // indirect
go.opentelemetry.io/collector/internal/memorylimiter v0.112.0 // indirect
go.opentelemetry.io/collector/pipeline/pipelineprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/processor/processorprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/processor/processortest v0.112.0 // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.112.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.7.0 // indirect
)
Expand Down Expand Up @@ -915,18 +915,6 @@ replace (
github.com/prometheus/node_exporter => github.com/grafana/node_exporter v0.18.1-grafana-r01.0.20231004161416-702318429731
)

// Replacing for an internal fork which allows us to observe metrics produced by the Collector.
// This is a temporary solution while a new configuration design is discussed for the collector. Related issues:
// https://github.com/open-telemetry/opentelemetry-collector/issues/7532
// https://github.com/open-telemetry/opentelemetry-collector/pull/7644
// https://github.com/open-telemetry/opentelemetry-collector/pull/7696
// https://github.com/open-telemetry/opentelemetry-collector/issues/4970
replace (
go.opentelemetry.io/collector/otelcol => github.com/grafana/opentelemetry-collector/otelcol v0.0.0-20241104164848-8ea9d0a3e17a
go.opentelemetry.io/collector/processor/batchprocessor => github.com/grafana/opentelemetry-collector/processor/batchprocessor v0.0.0-20241104164848-8ea9d0a3e17a
go.opentelemetry.io/collector/service => github.com/grafana/opentelemetry-collector/service v0.0.0-20241104164848-8ea9d0a3e17a
)

replace github.com/github/smimesign => github.com/grafana/smimesign v0.2.1-0.20220408144937-2a5adf3481d3

// Submodules.
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1252,12 +1252,6 @@ github.com/grafana/opentelemetry-collector-contrib/receiver/prometheusreceiver v
github.com/grafana/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.0.0-20240326165551-1ae1b9218b1b/go.mod h1:XVaL+FyxEWEfHkDI/X6FJgFYDA0080A1/qoOHQ43dxM=
github.com/grafana/opentelemetry-collector/featuregate v0.0.0-20240325174506-2fd1623b2ca0 h1:i/Ne0XwoRokYj52ZcSmnvuyID3h/uA91n0Ycg/grHU8=
github.com/grafana/opentelemetry-collector/featuregate v0.0.0-20240325174506-2fd1623b2ca0/go.mod h1:mm8+xyQfgDmqhyegZRNIQmoKsNnDTwWKFLsdMoXAb7A=
github.com/grafana/opentelemetry-collector/otelcol v0.0.0-20241104164848-8ea9d0a3e17a h1:6TnkhPwEjuleHfhKSw+IyC/I2cQORuEsImZZMhoodIE=
github.com/grafana/opentelemetry-collector/otelcol v0.0.0-20241104164848-8ea9d0a3e17a/go.mod h1:H/HurP0qCcwcWdDRgvTJ/FRrVLnt++agxzHvgLQn/Ew=
github.com/grafana/opentelemetry-collector/processor/batchprocessor v0.0.0-20241104164848-8ea9d0a3e17a h1:WrDY3pU4EkHsCIepUAYWt7lIfsMEPdugmYB8k6RYjMo=
github.com/grafana/opentelemetry-collector/processor/batchprocessor v0.0.0-20241104164848-8ea9d0a3e17a/go.mod h1:QLQ31rGjPuMc/nGw4rL4HzQI9F0jVAPEmC342chxoqA=
github.com/grafana/opentelemetry-collector/service v0.0.0-20241104164848-8ea9d0a3e17a h1:ZycgUSrrwtB2x1fMdLD88J2k8886/HvX1tYHlaOH/hg=
github.com/grafana/opentelemetry-collector/service v0.0.0-20241104164848-8ea9d0a3e17a/go.mod h1:VTLnax+DjHal3q7WKQO0ITjWdfPTq2txaoNRcVXYzgE=
github.com/grafana/postgres_exporter v0.15.1-0.20241105053755-e0a51174f168 h1:I7FyVTtge/3G5YHVOMDG0l4If6W+kXbFDqtzj5gCSGs=
github.com/grafana/postgres_exporter v0.15.1-0.20241105053755-e0a51174f168/go.mod h1:dMrETGkSetWByp2XGsm8g6pRVh/ibnrDxKsN4BqnGNg=
github.com/grafana/prometheus v1.8.2-0.20240514135907-13889ba362e6 h1:kih3d3M3dxAmrpFLvnIxFzWx8KMQyKxQwKgWP67C/Fg=
Expand Down Expand Up @@ -2686,6 +2680,8 @@ go.opentelemetry.io/collector/filter v0.112.0 h1:xX0MIfXOkbcWzCcmNqvtpnBDnSZAJmN
go.opentelemetry.io/collector/filter v0.112.0/go.mod h1:ZcPbD9CLxqcQJ5D2dV2Ma0Hm2IKMOYggTLW8dDdZQSQ=
go.opentelemetry.io/collector/internal/memorylimiter v0.112.0 h1:u1hUa48x1qEONUSOtz8dx/c8oz74RpIHyWnGFJ7t0CE=
go.opentelemetry.io/collector/internal/memorylimiter v0.112.0/go.mod h1:BtHruDt40QTW8klZVQCqsVfhVsOkh6hDg5w1cPvLpeU=
go.opentelemetry.io/collector/otelcol v0.112.0 h1:xOq7z5WK5jS1Qg5w+l99H1EiQRq9rHHDv7EIiLryldw=
go.opentelemetry.io/collector/otelcol v0.112.0/go.mod h1:H/HurP0qCcwcWdDRgvTJ/FRrVLnt++agxzHvgLQn/Ew=
go.opentelemetry.io/collector/otelcol/otelcoltest v0.112.0 h1:AdjoVnYl7RxoOvhWZcJb0SWY1VvlRT1cdlCwHBpn9vs=
go.opentelemetry.io/collector/otelcol/otelcoltest v0.112.0/go.mod h1:VSbEYgmiSM5K6p501XD35QuhxbDpkxrfS2Wf5OKnHPs=
go.opentelemetry.io/collector/pdata v1.18.0 h1:/yg2rO2dxqDM2p6GutsMCxXN6sKlXwyIz/ZYyUPONBg=
Expand All @@ -2700,6 +2696,8 @@ go.opentelemetry.io/collector/pipeline/pipelineprofiles v0.112.0 h1:opXGNrlJAjYR
go.opentelemetry.io/collector/pipeline/pipelineprofiles v0.112.0/go.mod h1:c9yn4x+vY3G10eLCRuUu/oH7Y8YdE/BsgmLWmfHkaNY=
go.opentelemetry.io/collector/processor v0.112.0 h1:nMv9DOBYR9MB78ddUgY3A3ytwAwk3t4HQMNIu+w8o0g=
go.opentelemetry.io/collector/processor v0.112.0/go.mod h1:AJ8EHq8Z/ev90f4gU6G5ULUncdpWmBRATYk8ioR3pvw=
go.opentelemetry.io/collector/processor/batchprocessor v0.112.0 h1:Dq/RpdClawI8HrnSi177LziPjfHo733BWOCgRTbWrfY=
go.opentelemetry.io/collector/processor/batchprocessor v0.112.0/go.mod h1:QLQ31rGjPuMc/nGw4rL4HzQI9F0jVAPEmC342chxoqA=
go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.112.0 h1:+V+4OUcg1s3CrZpttT4dA+Uuv7VWpOIPQpOkcsrMBIo=
go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.112.0/go.mod h1:f/eEZ3JMbRNLsRzNwATtTjuulDrLvhYMvXinLrmHtTU=
go.opentelemetry.io/collector/processor/processorprofiles v0.112.0 h1:Aef68SAbmBbhbsZZPuZb0ECwkV05vIcHIizGOGbWsbM=
Expand All @@ -2714,6 +2712,8 @@ go.opentelemetry.io/collector/receiver/receiverprofiles v0.112.0 h1:SShkZsWRsFss
go.opentelemetry.io/collector/receiver/receiverprofiles v0.112.0/go.mod h1:615smszDXiz4YWwXslxlAjX7FzOVDU7Bk6xARFk+zpk=
go.opentelemetry.io/collector/semconv v0.112.0 h1:JPQyvZhlNLVSuVI+FScONaiFygB7h7NTZceUEKIQUEc=
go.opentelemetry.io/collector/semconv v0.112.0/go.mod h1:zCJ5njhWpejR+A40kiEoeFm1xq1uzyZwMnRNX6/D82A=
go.opentelemetry.io/collector/service v0.112.0 h1:SI5bwPrRHLRn/kR9AoSSDX/8vaKFe+NMYloAcXfWMSE=
go.opentelemetry.io/collector/service v0.112.0/go.mod h1:VTLnax+DjHal3q7WKQO0ITjWdfPTq2txaoNRcVXYzgE=
go.opentelemetry.io/contrib/config v0.10.0 h1:2JknAzMaYjxrHkTnZh3eOme/Y2P5eHE2SWfhfV6Xd6c=
go.opentelemetry.io/contrib/config v0.10.0/go.mod h1:aND2M6/KfNkntI5cyvHriR/zvZgPf8j9yETdSmvpfmc=
go.opentelemetry.io/contrib/detectors/aws/ec2 v1.28.0 h1:d+y/wygENfwEbVpo7c3A9GfnMhoTiepQcthQSh+Mc9g=
Expand Down
3 changes: 2 additions & 1 deletion internal/static/traces/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (

"github.com/grafana/alloy/internal/static/logs"
"github.com/grafana/alloy/internal/static/traces/automaticloggingprocessor"
"github.com/grafana/alloy/internal/static/traces/forked_otelcol"
"github.com/grafana/alloy/internal/static/traces/noopreceiver"
"github.com/grafana/alloy/internal/static/traces/promsdprocessor"
"github.com/grafana/alloy/internal/static/traces/pushreceiver"
Expand Down Expand Up @@ -1003,7 +1004,7 @@ func orderProcessors(processors []string, splitPipelines bool) [][]string {

func otelcolConfigFromStringMap(otelMapStructure map[string]interface{}, factories *otelcol.Factories) (*otelcol.Config, error) {
configMap := confmap.NewFromStringMap(otelMapStructure)
otelCfg, err := otelcol.Unmarshal(configMap, *factories)
otelCfg, err := forked_otelcol.Unmarshal(configMap, *factories)
if err != nil {
return nil, fmt.Errorf("failed to load OTel config: %w", err)
}
Expand Down
11 changes: 11 additions & 0 deletions internal/static/traces/forked_configunmarshaler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The code was copied from:
https://github.com/open-telemetry/opentelemetry-collector/tree/v0.114.0/otelcol/internal/configunmarshaler

This forked package exists because the "forked_otelcol" package depends on it.

There is no need to update it every time Alloy's OTel version is updated:
* This is very fundamental code which doesn't change often.
* As long as Static mode's code still behaves as expected and the converter tests pass, that's fine.
* The version of OTel which Agent's repo uses is different from the one which Alloy uses anyway.

The only time when this forked package may need updating is when it fails to build due to refactoring in the OTel repo.
76 changes: 76 additions & 0 deletions internal/static/traces/forked_configunmarshaler/configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package forked_configunmarshaler // import "go.opentelemetry.io/collector/otelcol/internal/configunmarshaler"

import (
"errors"
"fmt"

"golang.org/x/exp/maps"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
)

type Configs[F component.Factory] struct {
cfgs map[component.ID]component.Config

factories map[component.Type]F
}

func NewConfigs[F component.Factory](factories map[component.Type]F) *Configs[F] {
return &Configs[F]{factories: factories}
}

func (c *Configs[F]) Unmarshal(conf *confmap.Conf) error {
rawCfgs := make(map[component.ID]map[string]any)
if err := conf.Unmarshal(&rawCfgs); err != nil {
return err
}

// Prepare resulting map.
c.cfgs = make(map[component.ID]component.Config)
// Iterate over raw configs and create a config for each.
for id := range rawCfgs {
// Find factory based on component kind and type that we read from config source.
factory, ok := c.factories[id.Type()]
if !ok {
return errorUnknownType(id, maps.Keys(c.factories))
}

// Get the configuration from the confmap.Conf to preserve internal representation.
sub, err := conf.Sub(id.String())
if err != nil {
return errorUnmarshalError(id, err)
}

// Create the default config for this component.
cfg := factory.CreateDefaultConfig()

// Now that the default config struct is created we can Unmarshal into it,
// and it will apply user-defined config on top of the default.
if err := sub.Unmarshal(&cfg); err != nil {
return errorUnmarshalError(id, err)
}

c.cfgs[id] = cfg
}

return nil
}

func (c *Configs[F]) Configs() map[component.ID]component.Config {
return c.cfgs
}

func errorUnknownType(id component.ID, factories []component.Type) error {
if id.Type().String() == "logging" {
return errors.New("the logging exporter has been deprecated, use the debug exporter instead")
}
return fmt.Errorf("unknown type: %q for id: %q (valid values: %v)", id.Type(), id, factories)
}

func errorUnmarshalError(id component.ID, err error) error {
return fmt.Errorf("error reading configuration for %q: %w", id, err)
}
145 changes: 145 additions & 0 deletions internal/static/traces/forked_configunmarshaler/configs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package forked_configunmarshaler

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/connector/connectortest"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/extension/extensiontest"
"go.opentelemetry.io/collector/processor/processortest"
"go.opentelemetry.io/collector/receiver/receivertest"
)

var nopType = component.MustNewType("nop")

var testKinds = []struct {
kind string
factories map[component.Type]component.Factory
}{
{
kind: "receiver",
factories: map[component.Type]component.Factory{
nopType: receivertest.NewNopFactory(),
},
},
{
kind: "processor",
factories: map[component.Type]component.Factory{
nopType: processortest.NewNopFactory(),
},
},
{
kind: "exporter",
factories: map[component.Type]component.Factory{
nopType: exportertest.NewNopFactory(),
},
},
{
kind: "connector",
factories: map[component.Type]component.Factory{
nopType: connectortest.NewNopFactory(),
},
},
{
kind: "extension",
factories: map[component.Type]component.Factory{
nopType: extensiontest.NewNopFactory(),
},
},
}

func TestUnmarshal(t *testing.T) {
for _, tk := range testKinds {
t.Run(tk.kind, func(t *testing.T) {
cfgs := NewConfigs(tk.factories)
conf := confmap.NewFromStringMap(map[string]any{
"nop": nil,
"nop/my" + tk.kind: nil,
})
require.NoError(t, cfgs.Unmarshal(conf))

assert.Equal(t, map[component.ID]component.Config{
component.NewID(nopType): tk.factories[nopType].CreateDefaultConfig(),
component.NewIDWithName(nopType, "my"+tk.kind): tk.factories[nopType].CreateDefaultConfig(),
}, cfgs.Configs())
})
}
}

func TestUnmarshalError(t *testing.T) {
for _, tk := range testKinds {
t.Run(tk.kind, func(t *testing.T) {
var testCases = []struct {
name string
conf *confmap.Conf
// string that the error must contain
expectedError string
}{
{
name: "invalid-type",
conf: confmap.NewFromStringMap(map[string]any{
"nop": nil,
"/custom": nil,
}),
expectedError: "the part before / should not be empty",
},
{
name: "invalid-name-after-slash",
conf: confmap.NewFromStringMap(map[string]any{
"nop": nil,
"nop/": nil,
}),
expectedError: "the part after / should not be empty",
},
{
name: "unknown-type",
conf: confmap.NewFromStringMap(map[string]any{
"nosuch" + tk.kind: nil,
}),
expectedError: "unknown type: \"nosuch" + tk.kind + "\" for id: \"nosuch" + tk.kind + "\" (valid values: [nop])",
},
{
name: "duplicate",
conf: confmap.NewFromStringMap(map[string]any{
"nop /my" + tk.kind + " ": nil,
" nop/ my" + tk.kind: nil,
}),
expectedError: "duplicate name",
},
{
name: "invalid-section",
conf: confmap.NewFromStringMap(map[string]any{
"nop": map[string]any{
"unknown_section": tk.kind,
},
}),
expectedError: "error reading configuration for \"nop\"",
},
{
name: "invalid-sub-config",
conf: confmap.NewFromStringMap(map[string]any{
"nop": "tests",
}),
expectedError: "'[nop]' expected a map, got 'string'",
},
}

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
cfgs := NewConfigs(tk.factories)
err := cfgs.Unmarshal(tt.conf)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)
})
}
})
}
}
14 changes: 14 additions & 0 deletions internal/static/traces/forked_otelcol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
The code was copied from:
https://github.com/open-telemetry/opentelemetry-collector/blob/v0.114.0/otelcol/unmarshaler.go
https://github.com/open-telemetry/opentelemetry-collector/blob/v0.114.0/otelcol/unmarshaler_test.go
https://github.com/open-telemetry/opentelemetry-collector/blob/v0.114.0/otelcol/factories_test.go

The purpose of this forked package is to allow Static mode to use the "Unmarshal(...)" function.
In the original OTel repo it is internal (it's lowercase - "unmarshal(...)").

There is no need to update this forked package every time Alloy's OTel version is updated:
* This is very fundamental code which doesn't change often.
* As long as Static mode's code still behaves as expected and the converter tests pass, that's fine.
* The version of OTel which Agent's repo uses is different from the one which Alloy uses anyway.

The only time when this forked package may need updating is when it fails to build due to refactoring in the OTel repo.
Loading

0 comments on commit b51d740

Please sign in to comment.