-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[receiver/skywalking] Create skywalking component folder/structure #8107
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
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
3621312
remove usage of Deprecated LogRecord.Name field.
JaredTan95 e262fd7
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
JaredTan95 50eed02
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
JaredTan95 5d9b46d
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
JaredTan95 4146721
first PR for skywaling/tracing receiver
JaredTan95 3f41a22
Merge branch 'main' into sw_reciever
JaredTan95 000d0ef
add change log
JaredTan95 b6416ef
fix go mod
JaredTan95 c29e2df
fix go mod
JaredTan95 7e171cf
fix goimports order
JaredTan95 722be02
fix build
JaredTan95 f5b6cc8
fix build
JaredTan95 2beb6c4
add sum
JaredTan95 c1f948c
polish
JaredTan95 f275ee4
update go sum
JaredTan95 137b3ab
polish go mod.
JaredTan95 05adcd1
make goporto
JaredTan95 3908cb3
polish
JaredTan95 2973c4a
polish
JaredTan95 208d01c
Merge branch 'main' into sw_reciever
JaredTan95 ff8a324
fix lint
JaredTan95 1147f04
Merge branch 'sw_reciever' of https://github.com/JaredTan95/opentelem…
JaredTan95 ce48c7a
Update factory.go
JaredTan95 22f779c
fix lint
JaredTan95 a3086fd
fix fmt
JaredTan95 1b78e25
fix unit test
JaredTan95 d802117
fix typo
JaredTan95 75602c8
Update receiver/skywalkingreceiver/config.go
JaredTan95 e1851a8
Update receiver/skywalkingreceiver/trace_receiver.go
JaredTan95 46999e6
Update receiver/skywalkingreceiver/trace_receiver.go
JaredTan95 3bbac8d
Update receiver/skywalkingreceiver/factory_test.go
JaredTan95 0e64519
Update config.yaml
JaredTan95 7250215
Update receiver/skywalkingreceiver/trace_receiver.go
JaredTan95 6302a13
Merge branch 'main' into sw_reciever
JaredTan95 0389cd1
Merge branch 'main' into sw_reciever
JaredTan95 b66a00c
add more UT for trace receiver.
JaredTan95 7390a69
fix fmt and lint
JaredTan95 6e52c83
add version.
JaredTan95 fe680d1
add com
JaredTan95 255bf24
fix com
JaredTan95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
# Skywalking Receiver | ||
|
||
Receives trace data in [Skywalking](https://skywalking.apache.org/) format. | ||
|
||
Supported pipeline types: traces | ||
|
||
## ⚠️ Warning | ||
|
||
Note: This component is currently work in progress, and traces receiver is not yet fully functional. | ||
|
||
## Getting Started | ||
JaredTan95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
By default, the Skywalking receiver will not serve any protocol. A protocol must be | ||
named under the `protocols` object for the Skywalking receiver to start. The | ||
below protocols are supported, each supports an optional `endpoint` | ||
object configuration parameter. | ||
|
||
- `grpc` (default `endpoint` = 0.0.0.0:11800) | ||
- `http` (default `endpoint` = 0.0.0.0:12800) | ||
|
||
Examples: | ||
|
||
```yaml | ||
receivers: | ||
skywalking: | ||
protocols: | ||
grpc: | ||
endpoint: 0.0.0.0:11800 | ||
http: | ||
endpoint: 0.0.0.0:12800 | ||
|
||
service: | ||
pipelines: | ||
traces: | ||
receivers: [skywalking] | ||
``` |
This file contains hidden or 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,94 @@ | ||
// Copyright OpenTelemetry Authors | ||
// | ||
// Licensed 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 skywalkingreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/skywalkingreceiver" | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/config" | ||
JaredTan95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"go.opentelemetry.io/collector/config/configgrpc" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
) | ||
|
||
const ( | ||
// The config field id to load the protocol map from | ||
protocolsFieldName = "protocols" | ||
) | ||
|
||
// Protocols is the configuration for the supported protocols. | ||
type Protocols struct { | ||
GRPC *configgrpc.GRPCServerSettings `mapstructure:"grpc"` | ||
HTTP *confighttp.HTTPServerSettings `mapstructure:"http"` | ||
} | ||
|
||
// Config defines configuration for skywalking receiver. | ||
type Config struct { | ||
config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct | ||
Protocols `mapstructure:"protocols"` | ||
} | ||
|
||
var _ config.Receiver = (*Config)(nil) | ||
var _ config.Unmarshallable = (*Config)(nil) | ||
|
||
// Validate checks the receiver configuration is valid | ||
func (cfg *Config) Validate() error { | ||
if cfg.GRPC == nil && cfg.HTTP == nil { | ||
return fmt.Errorf("must specify at least one protocol when using the Skywalking receiver") | ||
} | ||
|
||
JaredTan95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if cfg.GRPC != nil { | ||
var err error | ||
if _, err = extractPortFromEndpoint(cfg.GRPC.NetAddr.Endpoint); err != nil { | ||
return fmt.Errorf("unable to extract port for the gRPC endpoint: %w", err) | ||
} | ||
} | ||
|
||
if cfg.HTTP != nil { | ||
if _, err := extractPortFromEndpoint(cfg.HTTP.Endpoint); err != nil { | ||
return fmt.Errorf("unable to extract port for the HTTP endpoint: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Unmarshal a config.Parser into the config struct. | ||
func (cfg *Config) Unmarshal(componentParser *config.Map) error { | ||
if componentParser == nil || len(componentParser.AllKeys()) == 0 { | ||
return fmt.Errorf("empty config for Skywalking receiver") | ||
} | ||
|
||
// UnmarshalExact will not set struct properties to nil even if no key is provided, | ||
// so set the protocol structs to nil where the keys were omitted. | ||
err := componentParser.UnmarshalExact(cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
protocols, err := componentParser.Sub(protocolsFieldName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !protocols.IsSet(protoGRPC) { | ||
cfg.GRPC = nil | ||
JaredTan95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if !protocols.IsSet(protoHTTP) { | ||
cfg.HTTP = nil | ||
} | ||
|
||
return nil | ||
} |
This file contains hidden or 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,68 @@ | ||
// Copyright OpenTelemetry Authors | ||
// | ||
// Licensed 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 skywalkingreceiver | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
JaredTan95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/config/configgrpc" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/config/confignet" | ||
"go.opentelemetry.io/collector/service/servicetest" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
factories, err := componenttest.NopFactories() | ||
assert.NoError(t, err) | ||
|
||
factory := NewFactory() | ||
factories.Receivers[typeStr] = factory | ||
cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
|
||
assert.Equal(t, len(cfg.Receivers), 3) | ||
|
||
r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "customname")].(*Config) | ||
assert.Equal(t, r1, | ||
&Config{ | ||
ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "customname")), | ||
Protocols: Protocols{ | ||
HTTP: &confighttp.HTTPServerSettings{ | ||
Endpoint: "0.0.0.0:12801", | ||
}, | ||
}, | ||
}) | ||
|
||
rDefaults := cfg.Receivers[config.NewComponentIDWithName(typeStr, "defaults")].(*Config) | ||
assert.Equal(t, rDefaults, | ||
&Config{ | ||
ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "defaults")), | ||
Protocols: Protocols{ | ||
GRPC: &configgrpc.GRPCServerSettings{ | ||
NetAddr: confignet.NetAddr{ | ||
Endpoint: defaultGRPCBindEndpoint, | ||
Transport: "tcp", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains hidden or 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,120 @@ | ||
// Copyright OpenTelemetry Authors | ||
// | ||
// Licensed 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 skywalkingreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/skywalkingreceiver" | ||
|
||
// This file implements factory for skywalking receiver. | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"strconv" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/config/configgrpc" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/config/confignet" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/receiver/receiverhelper" | ||
) | ||
|
||
const ( | ||
typeStr = "skywalking" | ||
|
||
// Protocol values. | ||
protoGRPC = "grpc" | ||
protoHTTP = "http" | ||
|
||
// Default endpoints to bind to. | ||
defaultGRPCBindEndpoint = "0.0.0.0:11800" | ||
defaultHTTPBindEndpoint = "0.0.0.0:12800" | ||
) | ||
|
||
// NewFactory creates a new Skywalking receiver factory. | ||
func NewFactory() component.ReceiverFactory { | ||
return receiverhelper.NewFactory( | ||
typeStr, | ||
createDefaultConfig, | ||
receiverhelper.WithTraces(createTracesReceiver)) | ||
} | ||
|
||
// CreateDefaultConfig creates the default configuration for Skywalking receiver. | ||
func createDefaultConfig() config.Receiver { | ||
return &Config{ | ||
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), | ||
Protocols: Protocols{ | ||
GRPC: &configgrpc.GRPCServerSettings{ | ||
NetAddr: confignet.NetAddr{ | ||
Endpoint: defaultGRPCBindEndpoint, | ||
Transport: "tcp", | ||
}, | ||
}, | ||
HTTP: &confighttp.HTTPServerSettings{ | ||
Endpoint: defaultHTTPBindEndpoint, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// createTracesReceiver creates a trace receiver based on provided config. | ||
func createTracesReceiver( | ||
_ context.Context, | ||
set component.ReceiverCreateSettings, | ||
cfg config.Receiver, | ||
nextConsumer consumer.Traces, | ||
) (component.TracesReceiver, error) { | ||
|
||
// Convert settings in the source c to configuration struct | ||
// that Skywalking receiver understands. | ||
rCfg := cfg.(*Config) | ||
|
||
var err error | ||
var c configuration | ||
// Set ports | ||
if rCfg.Protocols.GRPC != nil { | ||
c.CollectorGRPCServerSettings = *rCfg.Protocols.GRPC | ||
if c.CollectorGRPCPort, err = extractPortFromEndpoint(rCfg.Protocols.GRPC.NetAddr.Endpoint); err != nil { | ||
return nil, fmt.Errorf("unable to extract port for the gRPC endpoint: %w", err) | ||
} | ||
} | ||
|
||
if rCfg.Protocols.HTTP != nil { | ||
c.CollectorHTTPSettings = *rCfg.Protocols.HTTP | ||
if c.CollectorHTTPPort, err = extractPortFromEndpoint(rCfg.Protocols.HTTP.Endpoint); err != nil { | ||
return nil, fmt.Errorf("unable to extract port for the HTTP endpoint: %w", err) | ||
} | ||
} | ||
|
||
// Create the receiver. | ||
return newSkywalkingReceiver(rCfg.ID(), &c, nextConsumer, set), nil | ||
} | ||
|
||
// extract the port number from string in "address:port" format. If the | ||
// port number cannot be extracted returns an error. | ||
func extractPortFromEndpoint(endpoint string) (int, error) { | ||
JaredTan95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_, portStr, err := net.SplitHostPort(endpoint) | ||
if err != nil { | ||
return 0, fmt.Errorf("endpoint is not formatted correctly: %s", err.Error()) | ||
} | ||
port, err := strconv.ParseInt(portStr, 10, 0) | ||
if err != nil { | ||
return 0, fmt.Errorf("endpoint port is not a number: %s", err.Error()) | ||
} | ||
if port < 1 || port > 65535 { | ||
return 0, fmt.Errorf("port number must be between 1 and 65535") | ||
} | ||
return int(port), nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.