-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[connector/signaltometrics] Add boilerplate for the connector
- Loading branch information
Showing
21 changed files
with
585 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: new_component | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: signaltometricsconnector | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: New component for generating metrics from raw signals using user defined OTTL expressions. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [35930] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
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
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
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,25 @@ | ||
# Signal to metrics connector | ||
|
||
Signal to metrics connector produces metrics from all signal types (traces, logs, or metrics). | ||
|
||
<!-- status autogenerated section --> | ||
| Status | | | ||
| ------------- |-----------| | ||
| Distributions | [] | | ||
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aconnector%2Fsignaltometrics%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aconnector%2Fsignaltometrics) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aconnector%2Fsignaltometrics%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aconnector%2Fsignaltometrics) | | ||
|
||
[alpha]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#alpha | ||
|
||
## Supported Pipeline Types | ||
|
||
| [Exporter Pipeline Type] | [Receiver Pipeline Type] | [Stability Level] | | ||
| ------------------------ | ------------------------ | ----------------- | | ||
| traces | metrics | [alpha] | | ||
| logs | metrics | [alpha] | | ||
| metrics | metrics | [alpha] | | ||
|
||
[Exporter Pipeline Type]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md#exporter-pipeline-type | ||
[Receiver Pipeline Type]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md#receiver-pipeline-type | ||
[Stability Level]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#stability-levels | ||
<!-- end autogenerated section --> | ||
|
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,7 @@ | ||
package config // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector/config" | ||
|
||
type Config struct{} | ||
|
||
func (c *Config) Validate() 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,47 @@ | ||
package signaltometricsconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/connector" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type signalToMetrics struct { | ||
next consumer.Metrics | ||
logger *zap.Logger | ||
|
||
component.StartFunc | ||
component.ShutdownFunc | ||
} | ||
|
||
func newSignalToMetrics( | ||
set connector.Settings, | ||
next consumer.Metrics, | ||
) *signalToMetrics { | ||
return &signalToMetrics{ | ||
logger: set.Logger, | ||
next: next, | ||
} | ||
} | ||
|
||
func (sm *signalToMetrics) Capabilities() consumer.Capabilities { | ||
return consumer.Capabilities{MutatesData: false} | ||
} | ||
|
||
func (sm *signalToMetrics) ConsumeTraces(ctx context.Context, td ptrace.Traces) error { | ||
return nil | ||
} | ||
|
||
func (sm *signalToMetrics) ConsumeMetrics(ctx context.Context, m pmetric.Metrics) error { | ||
return nil | ||
} | ||
|
||
func (sm *signalToMetrics) ConsumeLogs(ctx context.Context, logs plog.Logs) 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,4 @@ | ||
//go:generate mdatagen metadata.yaml | ||
|
||
// Package signaltometricsconnector provides a stateless connector for generating metrics from raw signals. | ||
package signaltometricsconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector" |
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,54 @@ | ||
package signaltometricsconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/connector" | ||
"go.opentelemetry.io/collector/consumer" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector/config" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector/internal/metadata" | ||
) | ||
|
||
// NewFactory returns a ConnectorFactory. | ||
func NewFactory() connector.Factory { | ||
return connector.NewFactory( | ||
metadata.Type, | ||
createDefaultConfig, | ||
connector.WithTracesToMetrics(createTracesToMetrics, metadata.TracesToMetricsStability), | ||
connector.WithMetricsToMetrics(createMetricsToMetrics, metadata.MetricsToMetricsStability), | ||
connector.WithLogsToMetrics(createLogsToMetrics, metadata.LogsToMetricsStability), | ||
) | ||
} | ||
|
||
func createDefaultConfig() component.Config { | ||
return &config.Config{} | ||
} | ||
|
||
func createTracesToMetrics( | ||
_ context.Context, | ||
set connector.Settings, | ||
cfg component.Config, | ||
nextConsumer consumer.Metrics, | ||
) (connector.Traces, error) { | ||
return newSignalToMetrics(set, nextConsumer), nil | ||
} | ||
|
||
func createMetricsToMetrics( | ||
_ context.Context, | ||
set connector.Settings, | ||
cfg component.Config, | ||
nextConsumer consumer.Metrics, | ||
) (connector.Metrics, error) { | ||
return newSignalToMetrics(set, nextConsumer), nil | ||
} | ||
|
||
func createLogsToMetrics( | ||
_ context.Context, | ||
set connector.Settings, | ||
cfg component.Config, | ||
nextConsumer consumer.Metrics, | ||
) (connector.Logs, error) { | ||
return newSignalToMetrics(set, nextConsumer), 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,87 @@ | ||
package signaltometricsconnector | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/connector/connectortest" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector/internal/metadata" | ||
) | ||
|
||
func TestNewFactoryWithLogs(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
f func(*testing.T) | ||
}{ | ||
{ | ||
name: "factory_type", | ||
f: func(t *testing.T) { | ||
factory := NewFactory() | ||
require.EqualValues(t, metadata.Type, factory.Type()) | ||
}, | ||
}, | ||
{ | ||
name: "traces_to_metrics", | ||
f: func(t *testing.T) { | ||
mc, err := consumer.NewMetrics(func(context.Context, pmetric.Metrics) error { | ||
return nil | ||
}) | ||
require.NoError(t, err) | ||
|
||
factory := NewFactory() | ||
c, err := factory.CreateTracesToMetrics( | ||
context.Background(), | ||
connectortest.NewNopSettings(), | ||
factory.CreateDefaultConfig(), | ||
mc, | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, c) | ||
}, | ||
}, | ||
{ | ||
name: "logs_to_metrics", | ||
f: func(t *testing.T) { | ||
mc, err := consumer.NewMetrics(func(context.Context, pmetric.Metrics) error { | ||
return nil | ||
}) | ||
require.NoError(t, err) | ||
|
||
factory := NewFactory() | ||
c, err := factory.CreateLogsToMetrics( | ||
context.Background(), | ||
connectortest.NewNopSettings(), | ||
factory.CreateDefaultConfig(), | ||
mc, | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, c) | ||
}, | ||
}, | ||
{ | ||
name: "metrics_to_metrics", | ||
f: func(t *testing.T) { | ||
mc, err := consumer.NewMetrics(func(context.Context, pmetric.Metrics) error { | ||
return nil | ||
}) | ||
require.NoError(t, err) | ||
|
||
factory := NewFactory() | ||
c, err := factory.CreateMetricsToMetrics( | ||
context.Background(), | ||
connectortest.NewNopSettings(), | ||
factory.CreateDefaultConfig(), | ||
mc, | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, c) | ||
}, | ||
}, | ||
} { | ||
t.Run(tc.name, tc.f) | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
connector/signaltometricsconnector/generated_component_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.