Fix support for new line in config URI location (#6310)
Signed-off-by: Bogdan <bogdandrutu@gmail.com> Signed-off-by: Bogdan <bogdandrutu@gmail.com>
This commit is contained in:
parent
aa78209898
commit
77946260ea
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
## v0.62.1 Beta
|
||||
|
||||
- Fix support for new line in config URI location. (#6306)
|
||||
|
||||
## v0.62.0 Beta
|
||||
|
||||
### 🛑 Breaking changes 🛑
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ var (
|
|||
|
||||
// Scheme name consist of a sequence of characters beginning with a letter and followed by any
|
||||
// combination of letters, digits, plus ("+"), period ("."), or hyphen ("-").
|
||||
locationRegexp = regexp.MustCompile(`^(?P<Scheme>[A-Za-z][A-Za-z0-9+.-]+):(?P<OpaqueValue>.*)$`)
|
||||
// Need to match new line as well in the OpaqueValue, so setting the "s" flag. See https://pkg.go.dev/regexp/syntax.
|
||||
locationRegexp = regexp.MustCompile(`(?s:^(?P<Scheme>[A-Za-z][A-Za-z0-9+.-]+):(?P<OpaqueValue>.*)$)`)
|
||||
|
||||
errTooManyRecursiveExpansions = errors.New("too many recursive expansions")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -280,6 +280,14 @@ func TestResolver(t *testing.T) {
|
|||
assert.NoError(t, errC)
|
||||
}
|
||||
|
||||
func TestResolverNewLinesInOpaqueValue(t *testing.T) {
|
||||
_, err := NewResolver(ResolverSettings{
|
||||
URIs: []string{"mock:receivers:\n nop:\n"},
|
||||
Providers: makeMapProvidersMap(&mockProvider{retM: newConfFromFile(t, filepath.Join("testdata", "config.yaml"))}),
|
||||
Converters: nil})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestResolverNoLocations(t *testing.T) {
|
||||
_, err := NewResolver(ResolverSettings{
|
||||
URIs: []string{},
|
||||
|
|
|
|||
|
|
@ -16,13 +16,21 @@ package service
|
|||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
|
||||
"go.opentelemetry.io/collector/confmap/provider/yamlprovider"
|
||||
"go.opentelemetry.io/collector/service/telemetry"
|
||||
)
|
||||
|
||||
func TestConfigProviderValidationError(t *testing.T) {
|
||||
|
|
@ -39,3 +47,91 @@ func TestConfigProviderValidationError(t *testing.T) {
|
|||
|
||||
assert.NoError(t, cfgW.Shutdown(context.Background()))
|
||||
}
|
||||
|
||||
var configNop = &Config{
|
||||
Receivers: map[config.ComponentID]config.Receiver{config.NewComponentID("nop"): componenttest.NewNopReceiverFactory().CreateDefaultConfig()},
|
||||
Processors: map[config.ComponentID]config.Processor{config.NewComponentID("nop"): componenttest.NewNopProcessorFactory().CreateDefaultConfig()},
|
||||
Exporters: map[config.ComponentID]config.Exporter{config.NewComponentID("nop"): componenttest.NewNopExporterFactory().CreateDefaultConfig()},
|
||||
Extensions: map[config.ComponentID]config.Extension{config.NewComponentID("nop"): componenttest.NewNopExtensionFactory().CreateDefaultConfig()},
|
||||
Service: ConfigService{
|
||||
Extensions: []config.ComponentID{config.NewComponentID("nop")},
|
||||
Pipelines: map[config.ComponentID]*ConfigServicePipeline{
|
||||
config.NewComponentID("traces"): {
|
||||
Receivers: []config.ComponentID{config.NewComponentID("nop")},
|
||||
Processors: []config.ComponentID{config.NewComponentID("nop")},
|
||||
Exporters: []config.ComponentID{config.NewComponentID("nop")},
|
||||
},
|
||||
config.NewComponentID("metrics"): {
|
||||
Receivers: []config.ComponentID{config.NewComponentID("nop")},
|
||||
Processors: []config.ComponentID{config.NewComponentID("nop")},
|
||||
Exporters: []config.ComponentID{config.NewComponentID("nop")},
|
||||
},
|
||||
config.NewComponentID("logs"): {
|
||||
Receivers: []config.ComponentID{config.NewComponentID("nop")},
|
||||
Processors: []config.ComponentID{config.NewComponentID("nop")},
|
||||
Exporters: []config.ComponentID{config.NewComponentID("nop")},
|
||||
},
|
||||
},
|
||||
Telemetry: telemetry.Config{
|
||||
Logs: telemetry.LogsConfig{
|
||||
Level: zapcore.InfoLevel,
|
||||
Development: false,
|
||||
Encoding: "console",
|
||||
OutputPaths: []string{"stderr"},
|
||||
ErrorOutputPaths: []string{"stderr"},
|
||||
DisableCaller: false,
|
||||
DisableStacktrace: false,
|
||||
InitialFields: map[string]interface{}(nil),
|
||||
},
|
||||
Metrics: telemetry.MetricsConfig{
|
||||
Level: configtelemetry.LevelBasic,
|
||||
Address: "localhost:8888",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestConfigProviderYaml(t *testing.T) {
|
||||
yamlBytes, err := os.ReadFile(filepath.Join("testdata", "otelcol-nop.yaml"))
|
||||
require.NoError(t, err)
|
||||
|
||||
uriLocation := "yaml:" + string(yamlBytes)
|
||||
provider := yamlprovider.New()
|
||||
set := ConfigProviderSettings{
|
||||
ResolverSettings: confmap.ResolverSettings{
|
||||
URIs: []string{uriLocation},
|
||||
Providers: map[string]confmap.Provider{provider.Scheme(): provider},
|
||||
},
|
||||
}
|
||||
|
||||
cp, err := NewConfigProvider(set)
|
||||
require.NoError(t, err)
|
||||
|
||||
factories, err := componenttest.NopFactories()
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, err := cp.Get(context.Background(), factories)
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, configNop, cfg)
|
||||
}
|
||||
|
||||
func TestConfigProviderFile(t *testing.T) {
|
||||
uriLocation := "file:" + filepath.Join("testdata", "otelcol-nop.yaml")
|
||||
provider := fileprovider.New()
|
||||
set := ConfigProviderSettings{
|
||||
ResolverSettings: confmap.ResolverSettings{
|
||||
URIs: []string{uriLocation},
|
||||
Providers: map[string]confmap.Provider{provider.Scheme(): provider},
|
||||
},
|
||||
}
|
||||
|
||||
cp, err := NewConfigProvider(set)
|
||||
require.NoError(t, err)
|
||||
|
||||
factories, err := componenttest.NopFactories()
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, err := cp.Get(context.Background(), factories)
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, configNop, cfg)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue