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

[receiver/envoyals] init new receiver #37193

Merged
merged 16 commits into from
Jan 23, 2025
28 changes: 28 additions & 0 deletions .chloggen/anvoy-als-receiver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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: envoyalsreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note:
Add a new receiver for the Envoy ALS (Access Log Service).
evan-bradley marked this conversation as resolved.
Show resolved Hide resolved

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36464]

# (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: []
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ receiver/couchdbreceiver/ @open-telemetry/collector-cont
receiver/datadogreceiver/ @open-telemetry/collector-contrib-approvers @boostchicken @gouthamve @MovieStoreGuy
receiver/dockerstatsreceiver/ @open-telemetry/collector-contrib-approvers @jamesmoessis
receiver/elasticsearchreceiver/ @open-telemetry/collector-contrib-approvers @djaglowski
receiver/envoyalsreceiver/ @open-telemetry/collector-contrib-approvers @evan-bradley
receiver/expvarreceiver/ @open-telemetry/collector-contrib-approvers @jamesmoessis @MovieStoreGuy
receiver/filelogreceiver/ @open-telemetry/collector-contrib-approvers @djaglowski
receiver/filestatsreceiver/ @open-telemetry/collector-contrib-approvers @atoulme
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 @@ -218,6 +218,7 @@ body:
- receiver/datadog
- receiver/dockerstats
- receiver/elasticsearch
- receiver/envoyals
- receiver/expvar
- receiver/filelog
- receiver/filestats
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 @@ -212,6 +212,7 @@ body:
- receiver/datadog
- receiver/dockerstats
- receiver/elasticsearch
- receiver/envoyals
- receiver/expvar
- receiver/filelog
- receiver/filestats
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 @@ -212,6 +212,7 @@ body:
- receiver/datadog
- receiver/dockerstats
- receiver/elasticsearch
- receiver/envoyals
- receiver/expvar
- receiver/filelog
- receiver/filestats
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 @@ -217,6 +217,7 @@ body:
- receiver/datadog
- receiver/dockerstats
- receiver/elasticsearch
- receiver/envoyals
- receiver/expvar
- receiver/filelog
- receiver/filestats
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 @@ -152,6 +152,7 @@ receivers:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver v0.117.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver v0.117.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/elasticsearchreceiver v0.117.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/envoyalsreceiver v0.117.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/expvarreceiver v0.117.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v0.117.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filestatsreceiver v0.117.0
Expand Down Expand Up @@ -354,6 +355,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/ecsutil => ../../internal/aws/ecsutil
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/rabbitmqreceiver => ../../receiver/rabbitmqreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/elasticsearchreceiver => ../../receiver/elasticsearchreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/envoyalsreceiver => ../../receiver/envoyalsreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricsgenerationprocessor => ../../processor/metricsgenerationprocessor
- github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor => ../../processor/attributesprocessor
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlqueryreceiver => ../../receiver/sqlqueryreceiver
Expand Down
1 change: 1 addition & 0 deletions receiver/envoyalsreceiver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
46 changes: 46 additions & 0 deletions receiver/envoyalsreceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Envoy ALS(access log service) receiver

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [alpha]: logs |
| Distributions | [contrib], [k8s] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fenvoyals%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fenvoyals) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fenvoyals%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fenvoyals) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@evan-bradley](https://www.github.com/evan-bradley) |

[alpha]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#alpha
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[k8s]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-k8s
<!-- end autogenerated section -->

This is a receiver for the [Envoy gRPC ALS](https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/access_loggers/grpc/v3/als.proto#envoy-v3-api-msg-extensions-access-loggers-grpc-v3-httpgrpcaccesslogconfig) sink.
zirain marked this conversation as resolved.
Show resolved Hide resolved

Envoy ALS (Access Log Service) is a feature of Envoy Proxy that allows for the
centralized collection and management of access logs.

Instead of writing access logs to local files, Envoy can be configured to send these logs to a remote gRPC service.

This is particularly useful in distributed systems where centralized logging is required for monitoring, auditing, and debugging purposes.

[Istio](https://istio.io) and [Envoy Gateway](https://gateway.envoyproxy.io) support this feature with first class API.
evan-bradley marked this conversation as resolved.
Show resolved Hide resolved

## Getting Started

The settings are:

- `endpoint` (required, default = localhost:3500 for HTTP protocol, localhost:3600 gRPC protocol): host:port to which the receiver is going to receive data. See our [security best practices doc](https://opentelemetry.io/docs/security/config-best-practices/#protect-against-denial-of-service-attacks) to understand how to set the endpoint in different environments.
zirain marked this conversation as resolved.
Show resolved Hide resolved

Example:
```yaml
receivers:
envoyals:
endpoint: 0.0.0.0:3500
```

## Advanced Configuration

Several helper files are leveraged to provide additional capabilities automatically:
evan-bradley marked this conversation as resolved.
Show resolved Hide resolved

- [gRPC settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configgrpc/README.md) including CORS
- [TLS and mTLS settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/README.md)

90 changes: 90 additions & 0 deletions receiver/envoyalsreceiver/als.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 envoyalsreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/envoyalsreceiver"

import (
"context"
"errors"
"fmt"

alsv3 "github.com/envoyproxy/go-control-plane/envoy/service/accesslog/v3"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componentstatus"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.uber.org/zap"
"google.golang.org/grpc"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/envoyalsreceiver/internal/als"
)

type alsReceiver struct {
conf *Config
nextConsumer consumer.Logs
settings receiver.Settings
serverGRPC *grpc.Server

obsrepGRPC *receiverhelper.ObsReport
}

func (r *alsReceiver) Start(ctx context.Context, host component.Host) error {
var err error
r.serverGRPC, err = r.conf.ToServer(ctx, host, r.settings.TelemetrySettings)
if err != nil {
return fmt.Errorf("failed create grpc server error: %w", err)
}

alsv3.RegisterAccessLogServiceServer(r.serverGRPC, als.New(r.nextConsumer, r.obsrepGRPC))

err = r.startGRPCServer(ctx, host)
if err != nil {
return fmt.Errorf("failed to start grpc server error: %w", err)
}

return err
}

func (r *alsReceiver) startGRPCServer(ctx context.Context, host component.Host) error {
r.settings.Logger.Info("Starting GRPC server", zap.String("endpoint", r.conf.NetAddr.Endpoint))
listener, err := r.conf.NetAddr.Listen(ctx)
if err != nil {
return err
}

go func() {
if errGRPC := r.serverGRPC.Serve(listener); !errors.Is(errGRPC, grpc.ErrServerStopped) && errGRPC != nil {
componentstatus.ReportStatus(host, componentstatus.NewFatalErrorEvent(errGRPC))
}
}()
return nil
}

func (r *alsReceiver) Shutdown(_ context.Context) error {
if r.serverGRPC != nil {
r.serverGRPC.GracefulStop()
}

return nil
}

func newALSReceiver(cfg *Config, nextConsumer consumer.Logs, settings receiver.Settings) (*alsReceiver, error) {
r := &alsReceiver{
conf: cfg,
nextConsumer: nextConsumer,
settings: settings,
}

var err error
r.obsrepGRPC, err = receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{
ReceiverID: settings.ID,
Transport: "grpc",
ReceiverCreateSettings: settings,
})
if err != nil {
return nil, err
}

return r, nil
}
Loading
Loading