Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialise receiver/elasticapmreceiver #191

Merged
merged 10 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
git diff --exit-code || (echo 'go.mod/go.sum deps changes detected, please run "make gotidy" and commit the changes in this PR.' && exit 1)
- name: CodeGen
run: |
make -j2 gogenerate && make -j2 licence-update
make -j2 gogenerate && make -j2 license-update
if [[ -n $(git status -s) ]]; then
echo 'Generated code is out of date, please run "make generate" and commit the changes in this PR.'
exit 1
Expand Down
1 change: 1 addition & 0 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ TOOLS_BIN_DIR := $(SRC_ROOT)/.tools
TOOLS_MOD_REGEX := "\s+_\s+\".*\""
TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"" | grep -vE '/v[0-9]+$$')
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(shell echo $(TOOLS_PKG_NAMES))))
export PATH := $(TOOLS_BIN_DIR):$(PATH)

LINT := $(TOOLS_BIN_DIR)/golangci-lint
MISSPELL := $(TOOLS_BIN_DIR)/misspell
Expand Down
1 change: 1 addition & 0 deletions receiver/elasticapmreceiver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
30 changes: 30 additions & 0 deletions receiver/elasticapmreceiver/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 elasticapmreceiver // import "github.com/elastic/opentelemetry-collector-components/receiver/elasticapmreceiver"

import "go.opentelemetry.io/collector/config/confighttp"

// Config defines configuration for the Elastic APM receiver.
type Config struct {
confighttp.ServerConfig `mapstructure:",squash"`
}

// Validate checks the receiver configuration is valid.
func (cfg *Config) Validate() error {
return nil
}
21 changes: 21 additions & 0 deletions receiver/elasticapmreceiver/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 elasticapmreceiver implements a receiver for the Elastic APM agent protocol.
package elasticapmreceiver // import "github.com/elastic/opentelemetry-collector-components/receiver/elasticapmreceiver"
110 changes: 110 additions & 0 deletions receiver/elasticapmreceiver/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// 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 elasticapmreceiver // import "github.com/elastic/opentelemetry-collector-components/receiver/elasticapmreceiver"

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/elastic/opentelemetry-collector-components/receiver/elasticapmreceiver/internal/metadata"
"github.com/elastic/opentelemetry-collector-components/receiver/elasticapmreceiver/internal/sharedcomponent"
)

const (
defaultEndpoint = "localhost:8200"
)

// NewFactory creates a new factory for the elasticapm receiver.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithLogs(createLogsReceiver, metadata.LogsStability),
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
receiver.WithTraces(createTracesReceiver, metadata.TracesStability),
)
}

// createDefaultConfig creates a default config with the endpoint set to port 8200.
func createDefaultConfig() component.Config {
defaultServerConfig := confighttp.NewDefaultServerConfig()
defaultServerConfig.Endpoint = defaultEndpoint
return &Config{
ServerConfig: defaultServerConfig,
}
}

// createLogsReceiver creates a logs receiver with the given configuration.
func createLogsReceiver(
_ context.Context,
set receiver.Settings,
cfg component.Config,
consumer consumer.Logs,
) (receiver.Logs, error) {
oCfg := cfg.(*Config)
r, err := receivers.LoadOrStore(oCfg, func() (*elasticAPMReceiver, error) {
return newElasticAPMReceiver(oCfg, set)
})
if err != nil {
return nil, err
}
r.Unwrap().nextLogs = consumer
return r, nil
}

// createMetricsReceiver creates a metrics receiver with the given configuration.
func createMetricsReceiver(
_ context.Context,
set receiver.Settings,
cfg component.Config,
consumer consumer.Metrics,
) (receiver.Metrics, error) {
oCfg := cfg.(*Config)
r, err := receivers.LoadOrStore(oCfg, func() (*elasticAPMReceiver, error) {
return newElasticAPMReceiver(oCfg, set)
})
if err != nil {
return nil, err
}
r.Unwrap().nextMetrics = consumer
return r, nil
}

// createTracesReceiver creates a traces receiver with the given configuration.
func createTracesReceiver(
_ context.Context,
set receiver.Settings,
cfg component.Config,
consumer consumer.Traces,
) (receiver.Traces, error) {
oCfg := cfg.(*Config)
r, err := receivers.LoadOrStore(oCfg, func() (*elasticAPMReceiver, error) {
return newElasticAPMReceiver(oCfg, set)
})
if err != nil {
return nil, err
}
r.Unwrap().nextTraces = consumer
return r, nil
}

var receivers = sharedcomponent.NewMap[*Config, *elasticAPMReceiver]()
axw marked this conversation as resolved.
Show resolved Hide resolved
100 changes: 100 additions & 0 deletions receiver/elasticapmreceiver/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 receiver/elasticapmreceiver/generated_package_test.go

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

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

go 1.22.0

require (
github.com/elastic/apm-data v1.14.1
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/component/componentstatus v0.111.0
go.opentelemetry.io/collector/config/confighttp v0.111.0
go.opentelemetry.io/collector/confmap v1.17.0
go.opentelemetry.io/collector/consumer v0.111.0
go.opentelemetry.io/collector/consumer/consumertest v0.111.0
go.opentelemetry.io/collector/pdata v1.17.0
go.opentelemetry.io/collector/receiver v0.111.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
golang.org/x/sync v0.8.0
)

require (
github.com/armon/go-radix v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/elastic/go-sysinfo v1.7.1 // indirect
github.com/elastic/go-windows v1.0.1 // indirect
github.com/elastic/opentelemetry-lib v0.12.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // 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/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.10 // 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/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rs/cors v1.11.1 // indirect
go.elastic.co/apm/v2 v2.6.2 // indirect
go.elastic.co/fastjson v1.4.0 // indirect
go.opentelemetry.io/collector/client v1.17.0 // indirect
go.opentelemetry.io/collector/config/configauth v0.111.0 // indirect
go.opentelemetry.io/collector/config/configcompression v1.17.0 // indirect
go.opentelemetry.io/collector/config/configopaque v1.17.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/config/configtls v1.17.0 // indirect
go.opentelemetry.io/collector/config/internal v0.111.0 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.111.0 // indirect
go.opentelemetry.io/collector/extension v0.111.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.111.0 // indirect
go.opentelemetry.io/collector/internal/globalsignal v0.111.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.111.0 // indirect
go.opentelemetry.io/collector/pipeline v0.111.0 // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.0 // indirect
go.opentelemetry.io/collector/semconv v0.111.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v1.0.0 // indirect
)
Loading