-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/beats-otel-collector' into bea…
…ts-otel-collector
- Loading branch information
Showing
4 changed files
with
112 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,91 @@ | ||
package customProvider | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/elastic/beats/v7/libbeat/cfgfile" | ||
"github.com/elastic/beats/v7/libbeat/outputs/elasticsearch" | ||
"github.com/elastic/elastic-agent-libs/config" | ||
"github.com/go-viper/mapstructure/v2" | ||
"go.opentelemetry.io/collector/confmap" | ||
) | ||
|
||
const schemeName = "filebeat" | ||
|
||
type provider struct{} | ||
|
||
func NewFactory() confmap.ProviderFactory { | ||
return confmap.NewProviderFactory(newProvider) | ||
} | ||
|
||
func newProvider(confmap.ProviderSettings) confmap.Provider { | ||
return &provider{} | ||
} | ||
|
||
func (fmp *provider) Retrieve(_ context.Context, uri string, _ confmap.WatcherFunc) (*confmap.Retrieved, error) { | ||
if !strings.HasPrefix(uri, schemeName+":") { | ||
return nil, fmt.Errorf("%q uri is not supported by %q provider", uri, schemeName) | ||
} | ||
|
||
cfg, err := cfgfile.Load(filepath.Clean(uri[len(schemeName)+1:]), nil) | ||
if err != nil { | ||
return nil, err | ||
|
||
} | ||
|
||
esCfg, err := elasticsearch.ToOtelConfig(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var tempMap map[string]any | ||
err = mapstructure.Decode(esCfg, &tempMap) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
newCfg := config.NewConfig() | ||
newCfg.SetString("otelconsumer", -1, "") | ||
|
||
cfg.SetChild("output", -1, newCfg) | ||
|
||
var receiverMap map[string]any | ||
cfg.Unpack(&receiverMap) | ||
|
||
cfgMap := map[string]any{ | ||
"exporters": map[string]any{ | ||
"elasticsearch": tempMap, | ||
"debug": map[string]any{}, | ||
}, | ||
"receivers": map[string]any{ | ||
"filebeatreceiver": receiverMap, | ||
}, | ||
"service": map[string]any{ | ||
"pipeline": map[string]any{ | ||
"logs": map[string]any{ | ||
"exporters": []string{ | ||
"debug", | ||
}, | ||
"receivers": []string{"filebeatreceiver"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
s, _ := json.MarshalIndent(cfgMap, "", " ") | ||
|
||
fmt.Println(string(s)) | ||
return confmap.NewRetrieved(cfgMap) | ||
} | ||
|
||
func (*provider) Scheme() string { | ||
return schemeName | ||
} | ||
|
||
func (*provider) Shutdown(context.Context) error { | ||
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,13 @@ | ||
package customProvider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestBeatProvider(t *testing.T) { | ||
p := provider{} | ||
fmt.Println(p.Retrieve(context.Background(), "filebeat:/Users/khushijain/Documents/beats/x-pack/filebeat/filebeat.yml", 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