-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import of template processor and receiver
- Loading branch information
Showing
25 changed files
with
1,848 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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 filetemplateextension // import "github.com/elastic/opentelemetry-collector-components/extension/filetemplateextension" | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type Config struct { | ||
Path string `mapstructure:"path"` | ||
} | ||
|
||
func (c *Config) Validate() error { | ||
if c.Path == "" { | ||
return errors.New("path is required") | ||
} | ||
info, err := os.Stat(c.Path) | ||
if err != nil { | ||
return err | ||
} | ||
if !info.IsDir() { | ||
return fmt.Errorf("path (%s) must be a directory", c.Path) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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 filetemplateextension // import "github.com/elastic/opentelemetry-collector-components/extension/filetemplateextension" | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/confmap" | ||
"go.opentelemetry.io/collector/confmap/provider/fileprovider" | ||
|
||
"github.com/elastic/opentelemetry-collector-components/pkg/templates" | ||
) | ||
|
||
type fileTemplateExtension struct { | ||
config *Config | ||
} | ||
|
||
var _ templates.TemplateFinder = &fileTemplateExtension{} | ||
|
||
func newFileTemplateExtension(config *Config) *fileTemplateExtension { | ||
return &fileTemplateExtension{ | ||
config: config, | ||
} | ||
} | ||
|
||
func (e *fileTemplateExtension) FindTemplate(ctx context.Context, name, version string) (templates.Template, error) { | ||
path := filepath.Join(e.config.Path, name+".yml") | ||
_, err := os.Stat(path) | ||
if errors.Is(err, fs.ErrNotExist) { | ||
return nil, templates.ErrNotFound | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &templateFile{ | ||
path: path, | ||
}, nil | ||
} | ||
|
||
func (*fileTemplateExtension) Start(context.Context, component.Host) error { | ||
return nil | ||
} | ||
|
||
func (*fileTemplateExtension) Shutdown(context.Context) error { | ||
return nil | ||
} | ||
|
||
type templateFile struct { | ||
path string | ||
} | ||
|
||
func (t *templateFile) URI() string { | ||
return "file:" + t.path | ||
} | ||
|
||
func (t *templateFile) ProviderFactory() confmap.ProviderFactory { | ||
return fileprovider.NewFactory() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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 filetemplateextension // import "github.com/elastic/opentelemetry-collector-components/extension/filetemplateextension" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/extension" | ||
) | ||
|
||
var ( | ||
extensionType = component.MustNewType("file_templates") | ||
) | ||
|
||
const ( | ||
extensionStability = component.StabilityLevelAlpha | ||
) | ||
|
||
// NewFactory creates a factory for ack extension. | ||
func NewFactory() extension.Factory { | ||
return extension.NewFactory( | ||
extensionType, | ||
createDefaultConfig, | ||
createExtension, | ||
extensionStability, | ||
) | ||
} | ||
|
||
func createDefaultConfig() component.Config { | ||
return &Config{ | ||
Path: "templates", | ||
} | ||
} | ||
|
||
func createExtension(_ context.Context, _ extension.Settings, cfg component.Config) (extension.Extension, error) { | ||
return newFileTemplateExtension(cfg.(*Config)), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module github.com/elastic/opentelemetry-collector-components/extension/filetemplateextension | ||
|
||
go 1.22.1 | ||
|
||
require ( | ||
github.com/elastic/opentelemetry-collector-components/pkg/templates v0.0.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 | ||
) | ||
|
||
require ( | ||
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // 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/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/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/templatereceiver => ../../receiver/templatereceiver | ||
|
||
replace github.com/elastic/opentelemetry-collector-components/pkg/templates => ../../pkg/templates |
Oops, something went wrong.