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

feat(sumologicexporter)!: remove deprecated json_logs #1452

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .changelog/1452.breaking.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat(sumologicexporter)!: remove deprecated json_logs
10 changes: 10 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Upgrading

- [Upgrading to v0.95.0-sumo-0](#upgrading-to-v0950-sumo-0)
- [`sumologic` exporter: remove `json_logs`](#sumologic-exporter-remove-json_logs)
- [Upgrading to v0.94.0-sumo-0](#upgrading-to-v0940-sumo-0)
- [`servicegraph` processor: removed in favor of `servicegraph` connector](#servicegraph-processor-removed-in-favor-of-servicegraph-connector)
- [Upgrading to v0.92.0-sumo-0](#upgrading-to-v0920-sumo-0)
Expand Down Expand Up @@ -50,6 +52,14 @@
- [Removing unnecessary metadata using the resourceprocessor](#removing-unnecessary-metadata-using-the-resourceprocessor)
- [Moving record-level attributes used for metadata to the resource level](#moving-record-level-attributes-used-for-metadata-to-the-resource-level)

## Upgrading to v0.95.0-sumo-0

### `sumologic` exporter: remove `json_logs`

`json_logs` has been removed in favor of `transform` processor.

Please follow [the migration process](#sumologic-exporter-deprecate-json_logs)

## Upgrading to v0.94.0-sumo-0

### `servicegraph` processor: removed in favor of `servicegraph` connector
Expand Down
19 changes: 0 additions & 19 deletions pkg/exporter/sumologicexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,6 @@ exporters:
# default = true
clear_logs_timestamp: {true, false}

json_logs:
# defines which key will be used to attach the log body at.
# This option affects JSON log format only.
# By default this is "log".
log_key: <log>
# defines whether to include a timestamp field when sending
# JSON logs, which would contain UNIX epoch timestamp in milliseconds.
# This option affects JSON log format only.
# default = true.
add_timestamp: {true, false}
# when add_timestamp is set to true then this key defines what is the name
# of the timestamp key.
# default = "timestamp".
timestamp_key: <timestamp_key>
# When flatten_body is set to true and log is a map,
# log's body is going to be flattened and `log_key` won't be used
# default = false
flatten_body: {true, false}

# instructs sumologicexporter to use an edpoint automatically generated by
# sumologicextension;
# to use direct endpoint, set it `auth` to `null` and set the endpoint configuration
Expand Down
28 changes: 0 additions & 28 deletions pkg/exporter/sumologicexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,11 @@ type Config struct {
// By default this is true.
ClearLogsTimestamp bool `mapstructure:"clear_logs_timestamp"`

JSONLogs `mapstructure:"json_logs"`

// StickySessionEnabled defines if sticky session support is enable.
// By default this is false.
StickySessionEnabled bool `mapstructure:"sticky_session_enabled"`
}

type JSONLogs struct {
// LogKey defines which key will be used to attach the log body at.
// This option affects JSON log format only.
// By default this is "log".
LogKey string `mapstructure:"log_key"`
// AddTimestamp defines whether to include a timestamp field when sending
// JSON logs, which would contain UNIX epoch timestamp in milliseconds.
// This option affects JSON log format only.
// By default this is true.
AddTimestamp bool `mapstructure:"add_timestamp"`
// When add_timestamp is set to true then this key defines what is the name
// of the timestamp key.
// By default this is "timestamp".
TimestampKey string `mapstructure:"timestamp_key"`
// When flatten_body is set to true and log is a map,
// log's body is going to be flattened and `log_key` won't be used
// By default this is false.
FlattenBody bool `mapstructure:"flatten_body"`
}

// CreateDefaultHTTPClientSettings returns default http client settings
func CreateDefaultHTTPClientSettings() confighttp.HTTPClientSettings {
return confighttp.HTTPClientSettings{
Expand Down Expand Up @@ -230,12 +208,6 @@ const (
DefaultClearLogsTimestamp bool = true
// DefaultLogKey defines default LogKey value
DefaultLogKey string = "log"
// DefaultAddTimestamp defines default AddTimestamp value
DefaultAddTimestamp bool = true
// DefaultTimestampKey defines default TimestampKey value
DefaultTimestampKey string = "timestamp"
// DefaultFlattenBody defines default FlattenBody value
DefaultFlattenBody bool = false
// DefaultDropRoutingAttribute defines default DropRoutingAttribute
DefaultDropRoutingAttribute string = ""
// DefaultStickySessionEnabled defines default StickySessionEnabled value
Expand Down
8 changes: 1 addition & 7 deletions pkg/exporter/sumologicexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ func createDefaultConfig() component.Config {
MetricFormat: DefaultMetricFormat,
Client: DefaultClient,
ClearLogsTimestamp: DefaultClearLogsTimestamp,
JSONLogs: JSONLogs{
LogKey: DefaultLogKey,
AddTimestamp: DefaultAddTimestamp,
TimestampKey: DefaultTimestampKey,
FlattenBody: DefaultFlattenBody,
},
TraceFormat: OTLPTraceFormat,
TraceFormat: OTLPTraceFormat,

HTTPClientSettings: CreateDefaultHTTPClientSettings(),
BackOffConfig: configretry.NewDefaultBackOffConfig(),
Expand Down
7 changes: 1 addition & 6 deletions pkg/exporter/sumologicexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ func TestCreateDefaultConfig(t *testing.T) {
MetricFormat: "otlp",
Client: "otelcol",
ClearLogsTimestamp: true,
JSONLogs: JSONLogs{
LogKey: "log",
AddTimestamp: true,
TimestampKey: "timestamp",
},
TraceFormat: "otlp",
TraceFormat: "otlp",

HTTPClientSettings: confighttp.HTTPClientSettings{
Timeout: 30 * time.Second,
Expand Down
36 changes: 2 additions & 34 deletions pkg/exporter/sumologicexporter/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ type sender struct {
config *Config
client *http.Client
prometheusFormatter prometheusFormatter
jsonLogsConfig JSONLogs
dataUrlMetrics string
dataUrlLogs string
dataUrlTraces string
Expand Down Expand Up @@ -177,7 +176,6 @@ func newSender(
config: cfg,
client: cl,
prometheusFormatter: pf,
jsonLogsConfig: cfg.JSONLogs,
dataUrlMetrics: metricsUrl,
dataUrlLogs: logsUrl,
dataUrlTraces: tracesUrl,
Expand Down Expand Up @@ -358,25 +356,10 @@ func (s *sender) logToText(record plog.LogRecord) string {
func (s *sender) logToJSON(record plog.LogRecord) (string, error) {
recordCopy := plog.NewLogRecord()
record.CopyTo(recordCopy)
if s.jsonLogsConfig.AddTimestamp {
addJSONTimestamp(recordCopy.Attributes(), s.jsonLogsConfig.TimestampKey, recordCopy.Timestamp())
}

// Only append the body when it's not empty to prevent sending 'null' log.
if body := recordCopy.Body(); !isEmptyAttributeValue(body) {
if s.jsonLogsConfig.FlattenBody && body.Type() == pcommon.ValueTypeMap {
// Cannot use CopyTo, as it overrides data.orig's values
body.Map().Range(func(k string, v pcommon.Value) bool {
_, ok := recordCopy.Attributes().Get(k)

if !ok {
v.CopyTo(recordCopy.Attributes().PutEmpty(k))
}
return true
})
} else {
body.CopyTo(recordCopy.Attributes().PutEmpty(s.jsonLogsConfig.LogKey))
}
body.CopyTo(recordCopy.Attributes().PutEmpty(DefaultLogKey))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to handle somehow non-empty body. I fallbacked to default behaviour

}

nextLine := new(bytes.Buffer)
Expand All @@ -391,21 +374,6 @@ func (s *sender) logToJSON(record plog.LogRecord) (string, error) {
return strings.TrimSuffix(nextLine.String(), "\n"), nil
}

var timeZeroUTC = time.Unix(0, 0).UTC()

// addJSONTimestamp adds a timestamp field to record attribtues before sending
// out the logs as JSON.
// If the attached timestamp is equal to 0 (millisecond based UNIX timestamp)
// then send out current time formatted as milliseconds since January 1, 1970.
func addJSONTimestamp(attrs pcommon.Map, timestampKey string, pt pcommon.Timestamp) {
t := pt.AsTime()
if t == timeZeroUTC {
attrs.PutInt(timestampKey, time.Now().UnixMilli())
} else {
attrs.PutInt(timestampKey, t.UnixMilli())
}
}

func isEmptyAttributeValue(att pcommon.Value) bool {
switch att.Type() {
case pcommon.ValueTypeEmpty:
Expand All @@ -428,7 +396,7 @@ func isEmptyAttributeValue(att pcommon.Value) bool {
// returns array of records which has not been sent correctly and error
func (s *sender) sendNonOTLPLogs(ctx context.Context, rl plog.ResourceLogs, flds fields) ([]plog.LogRecord, error) {
if s.config.LogFormat == OTLPLogFormat {
return nil, fmt.Errorf("Attempting to send OTLP logs as non-OTLP data")
return nil, fmt.Errorf("attempting to send OTLP logs as non-OTLP data")
}

var (
Expand Down
Loading
Loading