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

[exporter/datasetexporter]: Add configuration options server_host and retry_shutdown_timeout #24415

Merged
Merged
Show file tree
Hide file tree
Changes from 89 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
ec8a980
DSET-3998 - export Logs resource info based on export_resource_in…
zdaratom-s1 Jun 7, 2023
b7b7c0e
DSET-3998 - simplify
zdaratom-s1 Jun 7, 2023
322c5b5
DSET-3998 - improve docs
zdaratom-s1 Jun 8, 2023
1e4eaa6
Fix log exporter to set AddEvents Event timestamp (ts) field to event
tomaz-s1 Jun 8, 2023
4ddc9c4
Merge pull request #1 from zdaratom/DSET-3998
zdaratom-s1 Jun 9, 2023
cef4e67
Merge branch 'datasetexporter-latest' of github.com:scalyr/openteleme…
tomaz-s1 Jun 9, 2023
21e9041
Add additional assertions.
tomaz-s1 Jun 9, 2023
e03e0e2
Remove dummy debug logs.
tomaz-s1 Jun 9, 2023
b9c138f
Merge pull request #2 from scalyr/event_no_timestamp_fix_use_occurenc…
tomaz-s1 Jun 9, 2023
a3d5e0d
Create export-logs-resource-info-based-configuration
zdaratom-s1 Jun 13, 2023
65e9b0c
address PR notes - fix changelog gen
zdaratom-s1 Jun 13, 2023
d6cc185
fix docs typo
zdaratom-s1 Jun 13, 2023
9f987ac
fix changelog file suffix
zdaratom-s1 Jun 13, 2023
52e8651
Remove "OtelExporter - Log -" suffix from the event "message" field.
tomaz-s1 Jun 20, 2023
1b05c78
Implement severity field handling and make sure we currently map OTel
tomaz-s1 Jun 20, 2023
4cd8258
Remove flags and flags.is_sampled field since it provides no additional
tomaz-s1 Jun 21, 2023
26aae4f
Merge branch 'open-telemetry:main' into datasetexporter-latest
zdaratom-s1 Jun 21, 2023
b5674e7
Merge branch 'open-telemetry:main' into datasetexporter-latest
zdaratom-s1 Jun 22, 2023
a80ac48
Update metadata and indicate plugin is distributed as part of otel
tomaz-s1 Jun 22, 2023
af8f099
Move default severity to be a module level constant instead of function
tomaz-s1 Jun 22, 2023
1e17c4a
Refactor / split otelSeverityToDataSetSeverity to two functions.
tomaz-s1 Jun 22, 2023
79120e7
Also add test cases for invalid values.
tomaz-s1 Jun 22, 2023
f20f199
Make it a module level constant.
tomaz-s1 Jun 22, 2023
206c8eb
Make dataset log levels constants for easier readability and maintaince
tomaz-s1 Jun 22, 2023
21c07be
Re-generate readme.
tomaz-s1 Jun 23, 2023
211db7e
Per PR review, add "map" suffix to the function names.
tomaz-s1 Jun 23, 2023
656cc5f
For readability, split different test scenarios in different test
tomaz-s1 Jun 23, 2023
401041d
Add changelog entry file.
tomaz-s1 Jun 23, 2023
292122c
Merge pull request #3 from scalyr/dataset_log_exporter_improvements
tomaz-s1 Jun 26, 2023
adf3b7d
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
tomaz-s1 Jun 26, 2023
fc14849
Merge branch 'datasetexporter-latest' into dataset_log_exporter_impro…
tomaz-s1 Jun 26, 2023
ae0730f
Use consistent name for "observed time" field and also make sure it's
tomaz-s1 Jun 27, 2023
11a425f
Update body / message field handling - we don't want to utilize
tomaz-s1 Jun 27, 2023
b578baf
Put functionality to decompose message / body field of a complex type
tomaz-s1 Jun 27, 2023
ec0f58b
Fix lint.
tomaz-s1 Jun 27, 2023
d284d14
Add missing code comment.
tomaz-s1 Jun 27, 2023
0bbaa50
Use a constant.
tomaz-s1 Jun 27, 2023
64a5d88
Allow user to control if scope info and attributes are exported with
tomaz-s1 Jun 27, 2023
6ca746d
Add changelog file.
tomaz-s1 Jun 27, 2023
4c2c1bd
Remove debugging change, make sure we don't set scope.name attribute if
tomaz-s1 Jun 27, 2023
893e44a
For consistency name the field "sca:observedTime" instead (we already
tomaz-s1 Jun 28, 2023
9d0a7cd
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
tomaz-s1 Jun 28, 2023
96e4652
Merge branch 'datasetexporter-latest' into improve_field_name_and_val…
tomaz-s1 Jun 28, 2023
ce4174d
Merge pull request #6 from scalyr/improve_field_name_and_value_serial…
tomaz-s1 Jun 29, 2023
f9a6298
Update dataet trace exporter plugin and get rid of client side
tomaz-s1 Jun 29, 2023
c27a621
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
tomaz-s1 Jun 29, 2023
d887b47
Remove trace config option which are not needed anymore and where there
tomaz-s1 Jun 30, 2023
f240c7b
Merge branch 'datasetexporter-latest' into datasetexporter_simplify_t…
tomaz-s1 Jun 30, 2023
0b6dd46
Add changelog file.
tomaz-s1 Jun 30, 2023
840a8f0
Merge pull request #7 from scalyr/datasetexporter_simplify_trace_expo…
tomaz-s1 Jul 3, 2023
d6dae0d
Merge branch 'open-telemetry:main' into datasetexporter-latest
martin-majlis-s1 Jul 4, 2023
c4f394a
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
tomaz-s1 Jul 5, 2023
9dc8a2f
Merge branch 'datasetexporter-latest' of github.com:scalyr/openteleme…
tomaz-s1 Jul 5, 2023
d68b4f8
Merge branch 'main' into datasetexporter-latest
tomaz-s1 Jul 7, 2023
9101b99
Merge branch 'open-telemetry:main' into datasetexporter-latest
martin-majlis-s1 Jul 7, 2023
3ddd96f
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
tomaz-s1 Jul 10, 2023
84e56ed
Merge branch 'open-telemetry:main' into datasetexporter-latest
martin-majlis-s1 Jul 10, 2023
dff5afb
DSET-4002: Extract serverHost from the logs and traces
martin-majlis-s1 Jul 10, 2023
262e9e1
Merge branch 'open-telemetry:main' into datasetexporter-latest
zdaratom-s1 Jul 11, 2023
1dacfb8
Merge branch 'datasetexporter-latest' into DSET-4002-datasetexporter-…
martin-majlis-s1 Jul 12, 2023
cd2188b
Update tests to test new functionality
martin-majlis-s1 Jul 12, 2023
38ef9ec
Revert changes in the go.sum files
martin-majlis-s1 Jul 12, 2023
864b671
Update only relevant go.sum files
martin-majlis-s1 Jul 12, 2023
0a5a252
Update README to contain info about new configuration options
martin-majlis-s1 Jul 12, 2023
2ac2e2e
Incorporate comments from the review
martin-majlis-s1 Jul 13, 2023
e23b53a
Update dependencies
martin-majlis-s1 Jul 13, 2023
503ebf4
Merge branch 'open-telemetry:main' into datasetexporter-latest
martin-majlis-s1 Jul 13, 2023
5afc571
[exporter/datasetexporter]: Call the currect function on shutdown
martin-majlis-s1 Jul 13, 2023
c2748ac
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
tomaz-s1 Jul 13, 2023
3bb6ca3
Merge branch 'datasetexporter-latest' into DSET-4002-datasetexporter-…
martin-majlis-s1 Jul 13, 2023
1cd7330
Fix merge conflicts
martin-majlis-s1 Jul 13, 2023
affa22c
Add missing change log entry
martin-majlis-s1 Jul 13, 2023
058ae04
Merge branch 'main' into DSET-4050-handle-sigint-sigterm
martin-majlis-s1 Jul 13, 2023
98a8cc8
Merge branch 'main' into DSET-4050-handle-sigint-sigterm
martin-majlis-s1 Jul 14, 2023
b130a26
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
tomaz-s1 Jul 14, 2023
0bf4013
Merge pull request #9 from scalyr/DSET-4050-handle-sigint-sigterm
martin-majlis-s1 Jul 17, 2023
56e4577
Merge branch 'datasetexporter-latest' into DSET-4002-datasetexporter-…
martin-majlis-s1 Jul 17, 2023
4fa4fb7
Fix depenedencies in to otelcontrib
martin-majlis-s1 Jul 17, 2023
455cbd7
Update documentation
martin-majlis-s1 Jul 17, 2023
e4903fc
Update go.sum files in the root and for configschema
martin-majlis-s1 Jul 17, 2023
99904eb
Use serverHost from the resource
martin-majlis-s1 Jul 18, 2023
ae6b682
Fix go.sum file
martin-majlis-s1 Jul 18, 2023
aceb28a
Update the code to also check host.name resource attribute
martin-majlis-s1 Jul 18, 2023
f87c4fc
Fix go.sum
martin-majlis-s1 Jul 18, 2023
bb4020a
Merge branch 'main' into DSET-4002-datasetexporter-user-server-host
martin-majlis-s1 Jul 20, 2023
51fec22
Fit another merge conflict
martin-majlis-s1 Jul 20, 2023
00f15bf
Fix failing test after the merge
martin-majlis-s1 Jul 20, 2023
f42ab98
Merge branch 'main' into DSET-4002-datasetexporter-user-server-host
martin-majlis-s1 Jul 25, 2023
0306633
Incorporates suggestions from PR
martin-majlis-s1 Jul 26, 2023
7e94a1f
Remove old stray changelog file.
tomaz-s1 Jul 27, 2023
8a0b4e7
Add changelog entry for the serverHost change.
tomaz-s1 Jul 27, 2023
a8bc8eb
Merge branch 'main' into DSET-4002-datasetexporter-user-server-host
martin-majlis-s1 Jul 27, 2023
d730262
Bump version of dataset-go from 0.0.10 to 0.0.11
martin-majlis-s1 Jul 27, 2023
e17fbd7
Make shutdown duration configurable
martin-majlis-s1 Jul 27, 2023
e156698
Merge branch 'main' into DSET-4002-datasetexporter-user-server-host
martin-majlis-s1 Jul 28, 2023
058c5a3
Merge branch 'main' into DSET-4002-datasetexporter-user-server-host
martin-majlis-s1 Jul 31, 2023
ec2af4e
Fix failing tests
martin-majlis-s1 Jul 31, 2023
c0e60c1
Merge branch 'main' into DSET-4002-datasetexporter-user-server-host
martin-majlis-s1 Aug 1, 2023
508b155
Merge branch 'main' into DSET-4002-datasetexporter-user-server-host
martin-majlis-s1 Aug 1, 2023
6936447
Merge branch 'main' into DSET-4002-datasetexporter-user-server-host
martin-majlis-s1 Aug 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .chloggen/export-logs-resource-info-based-configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datasetexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Allow include Logs resource info export to DataSet based on new export_resource_info_on_event configuration. Fix timestamp handling."
martin-majlis-s1 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: [20660]

# (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:
2 changes: 1 addition & 1 deletion cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ require (
github.com/relvacode/iso8601 v1.3.0 // indirect
github.com/rs/cors v1.9.0 // indirect
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14 // indirect
github.com/scalyr/dataset-go v0.0.9 // indirect
github.com/scalyr/dataset-go v0.0.10 // indirect
github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.5.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ require (
github.com/rs/cors v1.9.0 // indirect
github.com/samber/lo v1.37.0 // indirect
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14 // indirect
github.com/scalyr/dataset-go v0.0.9 // indirect
github.com/scalyr/dataset-go v0.0.10 // indirect
github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.5.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 64 additions & 5 deletions exporter/datasetexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ See the [Getting Started](https://app.scalyr.com/help/getting-started) guide.

If you do not want to specify `api_key` in the file, you can use the [builtin functionality](https://opentelemetry.io/docs/collector/configuration/#configuration-environment-variables) and use `api_key: ${env:DATASET_API_KEY}`.

### Server Host Settings

Specifying the server host is crucial for ensuring the correct functionality of DataSet.
DataSet expects the server host value to be provided in the `serverHost` attribute.
If the server host value is stored in a different attribute, you can use the [resourceprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/resourceprocessor/README.md) or [attributesprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/attributesprocessor) to copy it into the `serverHost` attribute.

You can also utilize the `server_host` settings (described below) to populate the serverHost attribute with different values.

The process of populating the serverHost attribute works as follows:

* If the `serverHost` attribute is specified and not empty in the log or trace, then it is used.
* If the `serverHost` attribute is specified and not empty in the [resource](https://opentelemetry.io/docs/specs/otel/resource/sdk/), then it is used.
* If the `host.name` attribute is specified and not empty in the [resource](https://opentelemetry.io/docs/specs/otel/resource/sdk/), then it is used.
* If the `server_host.server_host` setting is specified and not empty, then it is used.
* If `server_host.use_host_name` setting is set to `true`, the `hostname` of the node is used.

Make sure to provide the appropriate server host value in the `serverHost` attribute to ensure the proper functionality of DataSet and accurate handling of events.

### Optional Settings

- `buffer`:
Expand All @@ -34,16 +52,29 @@ If you do not want to specify `api_key` in the file, you can use the [builtin fu
- `retry_max_interval` (default = 30s): Is the upper bound on backoff.
- `retry_max_elapsed_time` (default = 300s): Is the maximum amount of time spent trying to send a buffer.
- `logs`:
- `export_resource_info_on_event` (default = false): Include resource info to DataSet Event while exporting Logs. This is especially useful when reducing DataSet billable log volume.
- `export_scope_info_on_event` (default = false): Include LogRecord scope information (if available) on the DataSet event.
- `decompose_complex_message_field` (default = true): Set this to false to disable decomposing complex body / message field types (e.g. a map) into separate fields.
- `export_scope_info_on_event` (default = false): Include LogRecord scope information (if available) on the DataSet event.
- `decompose_complex_message_field` (default = true): Set this to false to disable decomposing complex body / message field types (e.g. a map) into separate fields.
- `server_host`:
- `server_host` (default = ''): Specifies the server host to be used for the events.
- `use_hostname` (default = true): Determines whether the `hostname` of the node should be used as the server host for the events. When set to `true`, the node's `hostname` is automatically used.
- `retry_on_failure`: See [retry_on_failure](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md)
- `sending_queue`: See [sending_queue](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md)
- `timeout`: See [timeout](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md)

### Example

```yaml
processors:
attributes:
- key: serverHost
action: insert
from_attribute: container_id
resource:
attributes:
- key: serverHost
from_attribute: node_id
action: insert

exporters:
dataset/logs:
# DataSet API URL, https://app.eu.scalyr.com for DataSet EU instance
Expand All @@ -55,7 +86,13 @@ exporters:
max_lifetime: 5s
# Group data based on these attributes
group_by:
- attributes.container_id
- container_id
server_host:
# If the serverHost attribute is not specified or empty,
# use the value from the env variable SERVER_HOST
server_host: ${env:SERVER_HOST}
# If server_host is not set, use the hostname value
use_hostname: true

dataset/traces:
# DataSet API URL, https://app.eu.scalyr.com for DataSet EU instance
Expand All @@ -71,7 +108,7 @@ service:
pipelines:
logs:
receivers: [otlp]
processors: [batch]
processors: [batch, attributes]
# add dataset among your exporters
exporters: [dataset/logs]
traces:
Expand All @@ -80,3 +117,25 @@ service:
# add dataset among your exporters
exporters: [dataset/traces]
```

## Examples

### Handling `serverHost` Attribute

Based on the given configuration and scenarios, here's the expected behavior:
martin-majlis-s1 marked this conversation as resolved.
Show resolved Hide resolved

1. Resource: `{'node_id:' 'node-pay-01', 'host.name': 'host-pay-01'}`, Log: `{'container_id': 'cont-pay-01'}`, Env: `SERVER_HOST='server-pay-01'`, Hostname: `ip-172-31-27-19`
* Since the attribute `container_id` is set, `attributesprocessor` will copy this value to the `serverHost`.
* Used `serverHost` will be `cont-pay-01`.
2. Resource: `{'node_id': 'node-pay-01', 'host.name': 'host-pay-01'}`, Log: `{'attribute.foo': 'Bar'}`, Env: `SERVER_HOST='server-pay-01'`, Hostname: `ip-172-31-27-19`
* Since the resource attribute `node_id` is set, `resourceprocessor` will copy this value to the `serverHost`.
* Used `serverHost` will be `node-pay-01`.
3. Resource: `{'host.name': 'host-pay-01'}`, Log: `{'attribute.foo': 'Bar'}`, Env: `SERVER_HOST='server-pay-01'`, Hostname: `ip-172-31-27-19`
* Since the resource attribute `host.name` is set, it will be used.
* Used `serverHost` will be `host-pay-01`.
4. Resource: `{}`, Log: `{'attribute.foo': 'Bar'}`, Env: `SERVER_HOST='server-pay-01'`, Hostname: `ip-172-31-27-19`
* Since the attribute `container_id` is not set, the value from the environmental variable `SERVER_HOST` will be copied to the `serverHost`.
* Used `serverHost` will be `server-pay-01`.
5. Resource: `{}`, Log: `{'attribute.foo': 'Bar'}`, Env: `SERVER_HOST=''`, Hostname: `ip-172-31-27-19`
* Since the attribute `container_id` is not set and the environmental variable `SERVER_HOST` is empty, the `hostname` of the node (`ip-172-31-27-19`) will be used as the fallback value for `serverHost`.
* Used `serverHost` will be `ip-172-31-27-19`.
36 changes: 29 additions & 7 deletions exporter/datasetexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/scalyr/dataset-go/pkg/buffer"
"github.com/scalyr/dataset-go/pkg/buffer_config"
datasetConfig "github.com/scalyr/dataset-go/pkg/config"
"github.com/scalyr/dataset-go/pkg/server_host_config"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -78,12 +79,26 @@ func newDefaultBufferSettings() BufferSettings {
}
}

type ServerHostSettings struct {
UseHostName bool `mapstructure:"use_hostname"`
ServerHost string `mapstructure:"server_host"`
}

// newDefaultBufferSettings returns the default settings for BufferSettings.
func newDefaultServerHostSettings() ServerHostSettings {
return ServerHostSettings{
UseHostName: true,
ServerHost: "",
}
}

type Config struct {
DatasetURL string `mapstructure:"dataset_url"`
APIKey configopaque.String `mapstructure:"api_key"`
BufferSettings `mapstructure:"buffer"`
TracesSettings `mapstructure:"traces"`
LogsSettings `mapstructure:"logs"`
ServerHostSettings `mapstructure:"server_host"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
exporterhelper.TimeoutSettings `mapstructure:"timeout"`
Expand Down Expand Up @@ -116,11 +131,12 @@ func (c *Config) String() string {
s := ""
s += fmt.Sprintf("%s: %s; ", "DatasetURL", c.DatasetURL)
s += fmt.Sprintf("%s: %+v; ", "BufferSettings", c.BufferSettings)
s += fmt.Sprintf("%s: %+v; ", "LogsSettings", c.LogsSettings)
s += fmt.Sprintf("%s: %+v; ", "TracesSettings", c.TracesSettings)
s += fmt.Sprintf("%s: %+v; ", "ServerHostSettings", c.ServerHostSettings)
s += fmt.Sprintf("%s: %+v; ", "RetrySettings", c.RetrySettings)
s += fmt.Sprintf("%s: %+v; ", "QueueSettings", c.QueueSettings)
s += fmt.Sprintf("%s: %+v; ", "TimeoutSettings", c.TimeoutSettings)
s += fmt.Sprintf("%s: %+v", "LogsSettings", c.LogsSettings)
s += fmt.Sprintf("%s: %+v", "TimeoutSettings", c.TimeoutSettings)

return s
}
Expand All @@ -145,15 +161,21 @@ func (c *Config) convert() (*ExporterConfig, error) {
RetryMultiplier: backoff.DefaultMultiplier,
RetryRandomizationFactor: backoff.DefaultRandomizationFactor,
},
ServerHostSettings: server_host_config.DataSetServerHostSettings{
UseHostName: c.ServerHostSettings.UseHostName,
ServerHost: c.ServerHostSettings.ServerHost,
},
},
tracesSettings: c.TracesSettings,
logsSettings: c.LogsSettings,
tracesSettings: c.TracesSettings,
logsSettings: c.LogsSettings,
serverHostSettings: c.ServerHostSettings,
},
nil
}

type ExporterConfig struct {
datasetConfig *datasetConfig.DataSetConfig
tracesSettings TracesSettings
logsSettings LogsSettings
datasetConfig *datasetConfig.DataSetConfig
tracesSettings TracesSettings
logsSettings LogsSettings
serverHostSettings ServerHostSettings
}
8 changes: 6 additions & 2 deletions exporter/datasetexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ func TestConfigString(t *testing.T) {
MaxLifetime: 123,
GroupBy: []string{"field1", "field2"},
},
TracesSettings: TracesSettings{},
TracesSettings: TracesSettings{},
ServerHostSettings: ServerHostSettings{
ServerHost: "foo-bar",
UseHostName: false,
},
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
}

assert.Equal(t,
"DatasetURL: https://example.com; BufferSettings: {MaxLifetime:123ns GroupBy:[field1 field2] RetryInitialInterval:0s RetryMaxInterval:0s RetryMaxElapsedTime:0s}; TracesSettings: {}; RetrySettings: {Enabled:true InitialInterval:5s RandomizationFactor:0.5 Multiplier:1.5 MaxInterval:30s MaxElapsedTime:5m0s}; QueueSettings: {Enabled:true NumConsumers:10 QueueSize:1000 StorageID:<nil>}; TimeoutSettings: {Timeout:5s}; LogsSettings: {ExportResourceInfo:false ExportScopeInfo:false DecomposeComplexMessageField:false}",
"DatasetURL: https://example.com; BufferSettings: {MaxLifetime:123ns GroupBy:[field1 field2] RetryInitialInterval:0s RetryMaxInterval:0s RetryMaxElapsedTime:0s}; LogsSettings: {ExportResourceInfo:false ExportScopeInfo:false DecomposeComplexMessageField:false}; TracesSettings: {}; ServerHostSettings: {UseHostName:false ServerHost:foo-bar}; RetrySettings: {Enabled:true InitialInterval:5s RandomizationFactor:0.5 Multiplier:1.5 MaxInterval:30s MaxElapsedTime:5m0s}; QueueSettings: {Enabled:true NumConsumers:10 QueueSize:1000 StorageID:<nil>}; TimeoutSettings: {Timeout:5s}",
config.String(),
)
}
Expand Down
45 changes: 45 additions & 0 deletions exporter/datasetexporter/datasetexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"net/http"
"os"
"reflect"
"strconv"
"time"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/scalyr/dataset-go/pkg/api/add_events"
"github.com/scalyr/dataset-go/pkg/client"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.uber.org/zap"
"golang.org/x/time/rate"
)
Expand All @@ -25,6 +27,7 @@ type DatasetExporter struct {
logger *zap.Logger
session string
exporterCfg *ExporterConfig
serverHost string
}

func newDatasetExporter(entity string, config *Config, set exporter.CreateSettings) (*DatasetExporter, error) {
Expand Down Expand Up @@ -57,19 +60,33 @@ func newDatasetExporter(entity string, config *Config, set exporter.CreateSettin
return nil, fmt.Errorf("cannot create newDatasetExporter: %w", err)
}

serverHost, err := getServerHost(exporterCfg.serverHostSettings)
if err != nil {
logger.Error("Cannot get serverHost: ", zap.Error(err))
return nil, fmt.Errorf("Cannot get serverHost: %w", err)
}

return &DatasetExporter{
client: client,
limiter: rate.NewLimiter(100*rate.Every(1*time.Minute), 100), // 100 requests / minute
session: uuid.New().String(),
logger: logger,
exporterCfg: exporterCfg,
serverHost: serverHost,
}, nil
}

func (e *DatasetExporter) shutdown(context.Context) error {
return e.client.Shutdown()
}

func getServerHost(settings ServerHostSettings) (string, error) {
if len(settings.ServerHost) > 0 {
return settings.ServerHost, nil
}
return os.Hostname()
}

func sendBatch(events []*add_events.EventBundle, client *client.DataSetClient) error {
return client.AddEvents(events)
}
Expand Down Expand Up @@ -117,3 +134,31 @@ func updateWithPrefixedValues(target map[string]interface{}, prefix string, sepa

}
}

func inferServerHost(
resource pcommon.Resource,
attrs map[string]interface{},
serverHost string,
) string {
// first use value from the attribute serverHost
valA, okA := attrs[add_events.AttrServerHost]
if okA {
host := fmt.Sprintf("%v", valA)
if len(host) > 0 {
return host
}
}

// then use value from resource attributes - serverHost and host.name
for _, resKey := range []string{add_events.AttrServerHost, "host.name"} {
valR, okR := resource.Attributes().Get(resKey)
if okR {
host := valR.AsString()
if len(host) > 0 {
return host
}
}
}

return serverHost
}
13 changes: 7 additions & 6 deletions exporter/datasetexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ func NewFactory() exporter.Factory {

func createDefaultConfig() component.Config {
return &Config{
BufferSettings: newDefaultBufferSettings(),
TracesSettings: newDefaultTracesSettings(),
LogsSettings: newDefaultLogsSettings(),
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
BufferSettings: newDefaultBufferSettings(),
TracesSettings: newDefaultTracesSettings(),
LogsSettings: newDefaultLogsSettings(),
ServerHostSettings: newDefaultServerHostSettings(),
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
}
}

Expand Down
Loading
Loading