Skip to content

Commit

Permalink
[receiver/azureblob] First PR (#11872)
Browse files Browse the repository at this point in the history
 azureblobreceiver reads logs and traces from Azure Blob Storage.
 
Co-authored-by: Pablo Baeyens <[email protected]>

Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
eedorenko and mx-psi authored Aug 11, 2022
1 parent c4561ba commit e11aa63
Show file tree
Hide file tree
Showing 10 changed files with 601 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ receiver/awscontainerinsightreceiver/ @open-telemetry/collector-c
receiver/awsecscontainermetricsreceiver/ @open-telemetry/collector-contrib-approvers @Aneurysm9
receiver/awsfirehosereceiver/ @open-telemetry/collector-contrib-approvers @Aneurysm9
receiver/awsxrayreceiver/ @open-telemetry/collector-contrib-approvers @willarmiros
receiver/azureblobreceiver/ @open-telemetry/collector-contrib-approvers @eedorenko @mx-psi
receiver/bigipreceiver/ @open-telemetry/collector-contrib-approvers @djaglowski @StefanKurek
receiver/carbonreceiver/ @open-telemetry/collector-contrib-approvers @pjanotti
receiver/chronyreceiver/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @jamesmoessis
Expand Down
1 change: 1 addition & 0 deletions receiver/azureblobreceiver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
41 changes: 41 additions & 0 deletions receiver/azureblobreceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Azure Blob Receiver

| Status | |
| ------------------------ | ----------- |
| Stability |[development]|
| Supported pipeline types | logs,traces |
| Distributions | [contrib] |


This receiver reads logs and trace data from [Azure Blob Storage](https://azure.microsoft.com/services/storage/blobs/).

## Configuration

The following settings are required:

- `connection_string:` (no default): Azure Blob Storage connection key, which can be found in the Azure Blob Storage resource on the Azure Portal.
- `event_hub:`
` endpoint:` (no default): Azure Event Hub endpoint triggering on the `Blob Create` event

The following settings can be optionally configured:

- `logs:`
` container_name:` (default = "logs"): Name of the blob container with the logs
- `traces:`
` container_name:` (default = "traces"): Name of the blob container with the traces

Example:

```yaml
receivers:
azureblob:
connection_string: DefaultEndpointsProtocol=https;AccountName=accountName;AccountKey=+idLkHYcL0MUWIKYHm2j4Q==;EndpointSuffix=core.windows.net
event_hub:
endpoint: Endpoint=sb://oteldata.servicebus.windows.net/;SharedAccessKeyName=otelhubbpollicy;SharedAccessKey=mPJVubIK5dJ6mLfZo1ucsdkLysLSQ6N7kddvsIcmoEs=;EntityPath=otellhub
```
The receiver subscribes [on the events](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-event-overview) published by Azure Blob Storage and handled by Azure Event Hub. When it receives `Blob Create` event, it reads the logs or traces from a corresponding blob and deletes it after processing.




39 changes: 39 additions & 0 deletions receiver/azureblobreceiver/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package azureblobreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azureblobreceiver"

import (
"go.opentelemetry.io/collector/config"
)

type Config struct {
config.ReceiverSettings `mapstructure:",squash"`
ConnectionString string `mapstructure:"connection_string"`
EventHub EventHubConfig `mapstructure:"event_hub"`
Logs LogsConfig `mapstructure:"logs"`
Traces TracesConfig `mapstructure:"traces"`
}

type EventHubConfig struct {
EndPoint string `mapstructure:"endpoint"`
}

type LogsConfig struct {
ContainerName string `mapstructure:"container_name"`
}

type TracesConfig struct {
ContainerName string `mapstructure:"container_name"`
}
121 changes: 121 additions & 0 deletions receiver/azureblobreceiver/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package azureblobreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azureblobreceiver"

import (
"context"
"errors"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent"
)

const (
// The value of "type" key in configuration.
typeStr = "azureblob"
logsContainerName = "logs"
tracesContainerName = "traces"
)

var (
errUnexpectedConfigurationType = errors.New("failed to cast configuration to Azure Blob Config")
)

type blobReceiverFactory struct {
receivers *sharedcomponent.SharedComponents
}

// NewFactory returns a factory for Azure Blob receiver.
func NewFactory() component.ReceiverFactory {
f := &blobReceiverFactory{
receivers: sharedcomponent.NewSharedComponents(),
}

return component.NewReceiverFactory(
typeStr,
f.createDefaultConfig,
component.WithTracesReceiver(f.createTracesReceiver, component.StabilityLevelBeta),
component.WithLogsReceiver(f.createLogsReceiver, component.StabilityLevelBeta))
}

func (f *blobReceiverFactory) createDefaultConfig() config.Receiver {
return &Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)),
Logs: LogsConfig{ContainerName: logsContainerName},
Traces: TracesConfig{ContainerName: tracesContainerName},
}
}

func (f *blobReceiverFactory) createLogsReceiver(
ctx context.Context,
set component.ReceiverCreateSettings,
cfg config.Receiver,
nextConsumer consumer.Logs,
) (component.LogsReceiver, error) {

receiver, err := f.getReceiver(set, cfg)

if err != nil {
set.Logger.Error(err.Error())
return nil, err
}

return receiver, nil
}

func (f *blobReceiverFactory) createTracesReceiver(
ctx context.Context,
set component.ReceiverCreateSettings,
cfg config.Receiver,
nextConsumer consumer.Traces,
) (component.TracesReceiver, error) {

receiver, err := f.getReceiver(set, cfg)

if err != nil {
set.Logger.Error(err.Error())
return nil, err
}

return receiver, nil
}

func (f *blobReceiverFactory) getReceiver(
set component.ReceiverCreateSettings,
cfg config.Receiver) (component.Receiver, error) {

var err error
r := f.receivers.GetOrAdd(cfg, func() component.Component {
receiverConfig, ok := cfg.(*Config)

if !ok {
err = errUnexpectedConfigurationType
return nil
}

var receiver component.Receiver
receiver, err = newReceiver(*receiverConfig, set)
return receiver
})

if err != nil {
return nil, err
}

return r.Unwrap(), err
}
33 changes: 33 additions & 0 deletions receiver/azureblobreceiver/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azureblobreceiver

go 1.18

require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.57.2
go.opentelemetry.io/collector v0.57.2
)

require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf v1.4.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
go.opentelemetry.io/collector/pdata v0.57.2 // indirect
go.opentelemetry.io/otel v1.8.0 // indirect
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.opentelemetry.io/otel/trace v1.8.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
Loading

0 comments on commit e11aa63

Please sign in to comment.