Skip to content

Commit

Permalink
[receiver/envoyals] init new receiver (#37193)
Browse files Browse the repository at this point in the history
  • Loading branch information
zirain authored Jan 23, 2025
1 parent 68fa024 commit 11e18af
Show file tree
Hide file tree
Showing 25 changed files with 1,009 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .chloggen/anvoy-als-receiver.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: 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).

# 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 @@ -222,6 +222,7 @@ receiver/couchdbreceiver/ @open-telemetry
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 @@ -220,6 +220,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 @@ -214,6 +214,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 @@ -214,6 +214,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 @@ -219,6 +219,7 @@ body:
- receiver/datadog
- receiver/dockerstats
- receiver/elasticsearch
- receiver/envoyals
- receiver/expvar
- receiver/filelog
- receiver/filestats
Expand Down
1 change: 1 addition & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -355,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
44 changes: 44 additions & 0 deletions receiver/envoyalsreceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Envoy ALS(access log service) receiver

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [development]: logs |
| Distributions | [] |
| 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) |

[development]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development
<!-- 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.

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 OTLP and gRPC ALS with first class API.

## Getting Started

The settings are:

- `endpoint` (required, default = localhost:19001 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.

Example:
```yaml
receivers:
envoyals:
endpoint: 0.0.0.0:3500
```
## Advanced Configuration
Other options can be configured to support more advanced use cases:
- [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

0 comments on commit 11e18af

Please sign in to comment.