-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[exporter/azureblob] add implementation for azure blob exporter #38028
[exporter/azureblob] add implementation for azure blob exporter #38028
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of things from me:
- Could you please include some tests around this functionality?
- The consume methods looks like duplicated code, could they be collapse into one method?
My initial thoughts by doing something like:
func (t *T) ConsumeTraces(ctx context.Context, pt ptrace.Traces) error {
buf, err := t.marshalTraces(pt)
if err != nil {
return err
}
return t.consumeBuffer(ctx, buf)
}
func (t *T) consumeBuffer(ctx context.Context, buf []byte) error {
// blob creationtion here and uploading
return nil
}
var fileExtensionMap = map[string]string{ | ||
formatTypeJSON: "json", | ||
formatTypeProto: "pb", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the event that I have configured an extension to perform the marshalling, it may be straight up raw text, or some other format that doesn't match json or protobuf.
Is it possible for a user to define their own extension for the data written?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supported, it can support other encoding extension with below config. And updated descriptions in README.md
.
azureblob/1:
encodings:
logs: text_encoding
client *azblob.Client | ||
signal pipeline.Signal | ||
marshaller *marshaller | ||
blobNameTemplate *template.Template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you expand why there is a template here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed template.
return fmt.Errorf("failed to parse template: %w", err) | ||
} | ||
|
||
// create client based on auth type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment here to explain that this is only required until there is an azure auth extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments in Config.URL
.
func (e *azureBlobExporter) generateBlobName(data map[string]any) (string, error) { | ||
// Get current time | ||
now := time.Now() | ||
|
||
// Execute the template | ||
var result bytes.Buffer | ||
if err := e.blobNameTemplate.Execute(&result, data); err != nil { | ||
return "", fmt.Errorf("failed to execute template: %w", err) | ||
} | ||
|
||
blobStr := result.String() | ||
return now.Format(blobStr), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My assumption here is that this works in two parts?
Provide a directory key, and ensure the blob has a unique name to avoid any collisions with other exporters?
I am mildly concerned that using a template might be slow in the hot path, and it might be better to use a strings builder instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed template and use string operations directly.
return fmt.Errorf("failed to upload metrics data: %w", err) | ||
} | ||
|
||
e.logger.Info("Successfully exported metrics to Azure Blob Storage", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest changing this to debug by default, it is going to be very noisey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
} | ||
|
||
blobContentReader := bytes.NewReader(data) | ||
_, err = e.client.UploadStream(context.TODO(), e.config.Container.Traces, blobName, blobContentReader, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the provided context instead of using context.TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
…tor-contrib into azureblobexporter-second-PR
Thanks @MovieStoreGuy for the careful review! I've did some changes as below
I also validated using 2 Azure blob storage account. Pls help to take a look at your convenience. Thanks! |
…tor-contrib into azureblobexporter-second-PR
Please |
exporter/azureblobexporter/config.go
Outdated
Container *Container `mapstructure:"container"` | ||
Auth *Authentication `mapstructure:"auth"` | ||
|
||
// BlobNameFormat is the format of the blob name. It controls the uploaded blob name, e.g. "2006/01/02/metrics_15_04_05_{{.SerialNum}}.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is no longer accurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
return fmt.Errorf("failed to upload traces data: %w", err) | ||
} | ||
|
||
e.logger.Debug("Successfully exported traces to Azure Blob Storage", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message leftover from refactor, remove signal type from message and add it as a log attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making it an attribute will make querying the data easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found there's data_type
attribute which contains signal type info. I just updated the message and not adding signal
attribute.
assert.NoError(t, te.start(context.Background(), componenttest.NewNopHost())) | ||
} | ||
|
||
func TestExporterConsumeMetrics(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func TestExporterConsumeMetrics(t *testing.T) { | |
func TestExporterConsumeTelemetry(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the test function name
MetricsFormat: "2006/01/02/metrics_15_04_05_{{.SerialNum}}.{{.FileExtension}}", | ||
LogsFormat: "2006/01/02/logs_15_04_05_{{.SerialNum}}.{{.FileExtension}}", | ||
TracesFormat: "2006/01/02/traces_15_04_05_{{.SerialNum}}.{{.FileExtension}}", | ||
MetricsFormat: "2006/01/02/metrics_15_04_05.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should default have millisecond precision? For large workloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also serial number, maybe minutes is enough as default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also plan to support append blob feature, but will do it in another PR for future.
if encoding == nil { | ||
return nil, fmt.Errorf("unknown encoding %q", config.Encodings.Logs) | ||
} | ||
// cast with ok to avoid panics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're casting to avoid panics, we should check the ok and return an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
if m.tracesMarshaler == nil { | ||
return nil, errors.New("traces are not supported by encoding") | ||
} | ||
buf, err := m.tracesMarshaler.MarshalTraces(td) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can return here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes looks safe to merge as is, anything extra can be added in future Prs.
Please run |
…tor-contrib into azureblobexporter-second-PR
Thank you all for the careful review! Updated and pls take a look! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with one docs question. Marked as ready to merge as I'm fine with fixing it as a quick followup if a maintainer gets in here first and merges.
@@ -36,18 +36,38 @@ The following settings can be optionally configured and have default values: | |||
- traces_format (default `2006/01/02/traces_15_04_05_{{.SerialNum}}.{{.FileExtension}}`): blob name format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these documented defaults still correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, I'll fix them in future PR.
Description
Implementation of new component, azure blob exporter.
Link to tracking issue
Fixes #34319 .
Testing
Validated using different authentication, and tested using multiple azure blob accounts.
example config.
output.


Documentation
See
README.md