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

[connector/signaltometrics] Add boilerplate for the connector #36454

Merged
27 changes: 27 additions & 0 deletions .chloggen/add-signaltometrics-connector.yaml
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]
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ connector/otlpjsonconnector/ @open-telemetry/collector-cont
connector/roundrobinconnector/ @open-telemetry/collector-contrib-approvers @bogdandrutu
connector/routingconnector/ @open-telemetry/collector-contrib-approvers @jpkrohling @mwear
connector/servicegraphconnector/ @open-telemetry/collector-contrib-approvers @jpkrohling @mapno @JaredTan95
connector/signaltometricsconnector/ @open-telemetry/collector-contrib-approvers @ChrsMark @lahsivjar
connector/spanmetricsconnector/ @open-telemetry/collector-contrib-approvers @portertech @Frapschen
connector/sumconnector/ @open-telemetry/collector-contrib-approvers @greatestusername @shalper2 @crobert-1

Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ body:
- connector/roundrobin
- connector/routing
- connector/servicegraph
- connector/signaltometrics
- connector/spanmetrics
- connector/sum
- examples/demo
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ body:
- connector/roundrobin
- connector/routing
- connector/servicegraph
- connector/signaltometrics
- connector/spanmetrics
- connector/sum
- examples/demo
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ body:
- connector/roundrobin
- connector/routing
- connector/servicegraph
- connector/signaltometrics
- connector/spanmetrics
- connector/sum
- examples/demo
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/unmaintained.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ body:
- connector/roundrobin
- connector/routing
- connector/servicegraph
- connector/signaltometrics
- connector/spanmetrics
- connector/sum
- examples/demo
Expand Down
1 change: 1 addition & 0 deletions connector/signaltometricsconnector/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
26 changes: 26 additions & 0 deletions connector/signaltometricsconnector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@ChrsMark](https://www.github.com/ChrsMark), [@lahsivjar](https://www.github.com/lahsivjar) |

[development]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development

## Supported Pipeline Types

| [Exporter Pipeline Type] | [Receiver Pipeline Type] | [Stability Level] |
| ------------------------ | ------------------------ | ----------------- |
| traces | metrics | [development] |
| logs | metrics | [development] |
| metrics | metrics | [development] |

[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 -->

10 changes: 10 additions & 0 deletions connector/signaltometricsconnector/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package config // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector/config"

type Config struct{}
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved

func (c *Config) Validate() error {
return nil
}
50 changes: 50 additions & 0 deletions connector/signaltometricsconnector/connector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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(context.Context, ptrace.Traces) error {
return nil
}

func (sm *signalToMetrics) ConsumeMetrics(context.Context, pmetric.Metrics) error {
return nil
}

func (sm *signalToMetrics) ConsumeLogs(context.Context, plog.Logs) error {
return nil
}
7 changes: 7 additions & 0 deletions connector/signaltometricsconnector/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//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"
57 changes: 57 additions & 0 deletions connector/signaltometricsconnector/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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,
_ component.Config,
nextConsumer consumer.Metrics,
) (connector.Traces, error) {
return newSignalToMetrics(set, nextConsumer), nil
}

func createMetricsToMetrics(
_ context.Context,
set connector.Settings,
_ component.Config,
nextConsumer consumer.Metrics,
) (connector.Metrics, error) {
return newSignalToMetrics(set, nextConsumer), nil
}

func createLogsToMetrics(
_ context.Context,
set connector.Settings,
_ component.Config,
nextConsumer consumer.Metrics,
) (connector.Logs, error) {
return newSignalToMetrics(set, nextConsumer), nil
}
90 changes: 90 additions & 0 deletions connector/signaltometricsconnector/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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)
}
}
Loading
Loading