Skip to content

Commit

Permalink
Add a new provider for integrations as raw configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Sep 23, 2024
1 parent faa1035 commit 5678bd1
Show file tree
Hide file tree
Showing 12 changed files with 510 additions and 0 deletions.
2 changes: 2 additions & 0 deletions distributions/elastic-components/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist:
otelcol_version: 0.109.0

extensions:
- gomod: github.com/elastic/opentelemetry-collector-components/extension/configintegrationextension v0.0.0
- gomod: github.com/elastic/opentelemetry-collector-components/extension/fileintegrationextension v0.0.0

connectors:
Expand Down Expand Up @@ -38,6 +39,7 @@ providers:

replaces:
- github.com/elastic/opentelemetry-collector-components/connector/spanmetricsconnectorv2 => ../connector/spanmetricsconnectorv2
- github.com/elastic/opentelemetry-collector-components/extension/configintegrationextension => ../extension/configintegrationextension
- github.com/elastic/opentelemetry-collector-components/extension/fileintegrationextension => ../extension/fileintegrationextension
- github.com/elastic/opentelemetry-collector-components/internal/integrations => ../internal/integrations
- github.com/elastic/opentelemetry-collector-components/processor/elasticinframetricsprocessor => ../processor/elasticinframetricsprocessor
Expand Down
1 change: 1 addition & 0 deletions extension/configintegrationextension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
26 changes: 26 additions & 0 deletions extension/configintegrationextension/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package configintegrationextension // import "github.com/elastic/opentelemetry-collector-components/extension/fileintegrationextension"

type Config struct {
Integrations map[string]string `mapstructure:"integrations"`
}

func (c *Config) Validate() error {
return nil
}
21 changes: 21 additions & 0 deletions extension/configintegrationextension/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//go:generate mdatagen metadata.yaml

// Package configintegrationextension provides a source of integrations that obtain them from a local directory.
package configintegrationextension // import "github.com/elastic/opentelemetry-collector-components/extension/fileintegrationextension"
89 changes: 89 additions & 0 deletions extension/configintegrationextension/extension.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package configintegrationextension // import "github.com/elastic/opentelemetry-collector-components/extension/fileintegrationextension"

import (
"context"
"strings"

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

"github.com/elastic/opentelemetry-collector-components/internal/integrations"
)

type configTemplateExtension struct {
config *Config
}

var _ integrations.TemplateFinder = &configTemplateExtension{}

func newConfigTemplateExtension(config *Config) *configTemplateExtension {
return &configTemplateExtension{
config: config,
}
}

func (e *configTemplateExtension) FindTemplate(ctx context.Context, name, version string) (integrations.Template, error) {
integration, found := e.config.Integrations[name]
if !found {
return nil, integrations.ErrNotFound
}

return &integrationConfig{
name: name,
integration: strings.ReplaceAll(integration, `$$`, `$`),
}, nil
}

func (*configTemplateExtension) Start(context.Context, component.Host) error {
return nil
}

func (*configTemplateExtension) Shutdown(context.Context) error {
return nil
}

type integrationConfig struct {
name string
integration string
}

func (t *integrationConfig) URI() string {
return t.Scheme() + ":" + t.name
}

func (t *integrationConfig) ProviderFactory() confmap.ProviderFactory {
return t
}

func (t *integrationConfig) Create(_ confmap.ProviderSettings) confmap.Provider {
return t
}

func (t *integrationConfig) Retrieve(ctx context.Context, _ string, _ confmap.WatcherFunc) (*confmap.Retrieved, error) {
return confmap.NewRetrievedFromYAML([]byte(t.integration))
}

func (t *integrationConfig) Scheme() string {
return "config"
}

func (t *integrationConfig) Shutdown(ctx context.Context) error {
return nil
}
45 changes: 45 additions & 0 deletions extension/configintegrationextension/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package configintegrationextension // import "github.com/elastic/opentelemetry-collector-components/extension/fileintegrationextension"

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension"

"github.com/elastic/opentelemetry-collector-components/extension/configintegrationextension/internal/metadata"
)

// NewFactory creates a factory for ack extension.
func NewFactory() extension.Factory {
return extension.NewFactory(
metadata.Type,
createDefaultConfig,
createExtension,
metadata.ExtensionStability,
)
}

func createDefaultConfig() component.Config {
return &Config{}
}

func createExtension(_ context.Context, _ extension.Settings, cfg component.Config) (extension.Extension, error) {
return newConfigTemplateExtension(cfg.(*Config)), nil
}
66 changes: 66 additions & 0 deletions extension/configintegrationextension/generated_component_test.go

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

29 changes: 29 additions & 0 deletions extension/configintegrationextension/generated_package_test.go

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

60 changes: 60 additions & 0 deletions extension/configintegrationextension/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module github.com/elastic/opentelemetry-collector-components/extension/configintegrationextension

go 1.22.1

require (
github.com/elastic/opentelemetry-collector-components/internal/integrations v0.0.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.105.0
go.opentelemetry.io/collector/confmap v0.105.0
go.opentelemetry.io/collector/confmap/provider/fileprovider v0.105.0
go.opentelemetry.io/collector/extension v0.105.0
go.uber.org/goleak v1.3.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.105.0 // indirect
go.opentelemetry.io/collector/featuregate v1.13.0 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.105.0 // indirect
go.opentelemetry.io/collector/pdata v1.13.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.50.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/elastic/opentelemetry-collector-components/receiver/integrationreceiver => ../../receiver/integrationreceiver

replace github.com/elastic/opentelemetry-collector-components/internal/integrations => ../../internal/integrations
Loading

0 comments on commit 5678bd1

Please sign in to comment.