Skip to content

Commit

Permalink
[connector/signaltometrics] Add boilerplate for the connector
Browse files Browse the repository at this point in the history
  • Loading branch information
lahsivjar committed Nov 19, 2024
1 parent ca3c287 commit dd4cd8a
Show file tree
Hide file tree
Showing 21 changed files with 585 additions and 0 deletions.
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
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
25 changes: 25 additions & 0 deletions connector/signaltometricsconnector/README.md
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 -->

7 changes: 7 additions & 0 deletions connector/signaltometricsconnector/config/config.go
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
}
47 changes: 47 additions & 0 deletions connector/signaltometricsconnector/connector.go
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
}
4 changes: 4 additions & 0 deletions connector/signaltometricsconnector/doc.go
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"
54 changes: 54 additions & 0 deletions connector/signaltometricsconnector/factory.go
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
}
87 changes: 87 additions & 0 deletions connector/signaltometricsconnector/factory_test.go
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 connector/signaltometricsconnector/generated_component_test.go

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

Loading

0 comments on commit dd4cd8a

Please sign in to comment.