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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
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
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ connectors:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/connector/roundrobinconnector v0.114.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector v0.114.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/connector/servicegraphconnector v0.114.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector v0.114.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector v0.114.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/connector/sumconnector v0.114.0

Expand Down Expand Up @@ -465,6 +466,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/connector/roundrobinconnector => ../../connector/roundrobinconnector
- github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector => ../../connector/routingconnector
- github.com/open-telemetry/opentelemetry-collector-contrib/connector/servicegraphconnector => ../../connector/servicegraphconnector
- github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector => ../../connector/signaltometricsconnector
lahsivjar marked this conversation as resolved.
Show resolved Hide resolved
- github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector => ../../connector/spanmetricsconnector
- github.com/open-telemetry/opentelemetry-collector-contrib/connector/sumconnector => ../../connector/sumconnector
- github.com/openshift/api v3.9.0+incompatible => github.com/openshift/api v0.0.0-20180801171038-322a19404e37
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
27 changes: 27 additions & 0 deletions connector/signaltometricsconnector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Signal to metrics connector

Signal to metrics connector produces metrics from all signal types (traces, logs, or metrics).

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Distributions | [contrib] |
| 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
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib

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

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

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

import "fmt"

// Config for the connector. Each configuration field describes the metrics
// to produce from a specific signal.
type Config struct {
Spans []MetricInfo `mapstructure:"spans"`
Datapoints []MetricInfo `mapstructure:"datapoints"`
Logs []MetricInfo `mapstructure:"logs"`
}

func (c *Config) Validate() error {
if len(c.Spans) == 0 && len(c.Datapoints) == 0 && len(c.Logs) == 0 {
return fmt.Errorf("no configuration provided, at least one should be specified")
}
return nil
}

// MetricInfo defines the structure of the metric produced by the connector.
type MetricInfo struct {
Name string `mapstructure:"name"`
Description string `mapstructure:"description"`
// Unit, if not-empty, will set the unit associated with the metric.
// See: https://github.com/open-telemetry/opentelemetry-collector/blob/b06236cc794982916cc956f20828b3e18eb33264/pdata/pmetric/generated_metric.go#L72-L81
Unit string `mapstructure:"unit"`
// IncludeResourceAttributes is a list of resource attributes that
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved
// needs to be included in the generated metric. If no resource
// attribute is included in the list then all attributes are included.
// Metric data streams MUST obey single-writer. The component produces
// metrics from non-metric signals as well as alters resource attributes
// from the source signals. To keep the single-writer valid, the
lahsivjar marked this conversation as resolved.
Show resolved Hide resolved
// component adds collector information as resource attribute with the
// component name as the prefix of the resource attributes.
IncludeResourceAttributes []Attribute `mapstructure:"include_resource_attributes"`
Attributes []Attribute `mapstructure:"attributes"`
// Conditions are a set of OTTL condtions which are ORd. Data is
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved
lahsivjar marked this conversation as resolved.
Show resolved Hide resolved
// processed into metrics only if the sequence evaluates to true.
Conditions []string `mapstructure:"conditions"`
Histogram *Histogram `mapstructure:"histogram"`
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved
ExponentialHistogram *ExponentialHistogram `mapstructure:"exponential_histogram"`
Sum *Sum `mapstructure:"sum"`
}

type Attribute struct {
Key string `mapstructure:"key"`
DefaultValue any `mapstructure:"default_value"`
}

type Histogram struct {
Buckets []float64 `mapstructure:"buckets"`
Count string `mapstructure:"count"`
Value string `mapstructure:"value"`
}

type ExponentialHistogram struct {
MaxSize int32 `mapstructure:"max_size"`
Count string `mapstructure:"count"`
Value string `mapstructure:"value"`
}

type Sum struct {
Value string `mapstructure:"value"`
}
51 changes: 51 additions & 0 deletions connector/signaltometricsconnector/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package config

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"

"github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector/internal/metadata"
)

func TestConfig(t *testing.T) {
for _, tc := range []struct {
path string // relative to `testdata/configs` directory
expected *Config
errorMsgs []string // all error message are checked
}{
{
path: "empty",
errorMsgs: []string{"no configuration provided"},
},
} {
t.Run(tc.path, func(t *testing.T) {
dir := filepath.Join("..", "testdata", "configs")
cfg := &Config{}
cm, err := confmaptest.LoadConf(filepath.Join(dir, tc.path+".yaml"))
require.NoError(t, err)

sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String())
require.NoError(t, err)
require.NoError(t, sub.Unmarshal(&cfg))

err = component.ValidateConfig(cfg)
if len(tc.errorMsgs) > 0 {
for _, errMsg := range tc.errorMsgs {
assert.ErrorContains(t, err, errMsg)
}
return
}

assert.NoError(t, err)
assert.Equal(t, tc.expected, cfg)
})
}
}
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
}
Loading