forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[receiver/azureblob] First PR (#11872)
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
Showing
10 changed files
with
601 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.