Skip to content

Commit

Permalink
[exporter/loki] Remove deprecated configuration parameters (#20714)
Browse files Browse the repository at this point in the history
[exporter/loki] Remove deprecated configuration parameters. Closes #15365, #15653
  • Loading branch information
mar4uk authored Apr 10, 2023
1 parent 3dc9d21 commit 795a094
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 2,331 deletions.
17 changes: 17 additions & 0 deletions .chloggen/loki-remove-deprecated-parameters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove deprecated Loki exporters parameters.

# One or more tracking issues related to the change
issues: [15653, 15365]

# (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: The support of `labels.{attributes/resource}`, `labels.record`, `tenant`,
| and `format` configuration parameters are dropped in favor of attribute hints way of configuring the exporter.
8 changes: 0 additions & 8 deletions exporter/lokiexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ The following formats are supported:

OpenTelemetry uses `record.severity` to track log levels where loki uses `record.attributes.level` for the same. The exporter automatically maps the two, except if a "level" attribute already exists.

## Deprecated configuration
The following options are now deprecated:

- `labels.{attributes/resource}`. Deprecated and will be removed by v0.59.0. See the [Labels](#labels) section for more information.
- `labels.record`. Deprecated and will be removed by v0.59.0. See the [Labels](#labels) section for more information.
- `tenant`: Deprecated and will be removed by v0.59.0. See the [Tenant information](#tenant-information) section for more information.
- `format` Deprecated without replacement. See the [Format](#format) section for more information.

## Advanced Configuration

Several helper files are leveraged to provide additional capabilities automatically:
Expand Down
61 changes: 0 additions & 61 deletions exporter/lokiexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ type Config struct {
confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`

// TenantID defines the tenant ID to associate log streams with.
// Deprecated: [v0.57.0] use the attribute processor to add a `loki.tenant` hint.
// See this component's documentation for more information on how to specify the hint.
TenantID *string `mapstructure:"tenant_id"`

// Labels defines how labels should be applied to log streams sent to Loki.
// Deprecated: [v0.57.0] use the attribute processor to add a `loki.attribute.labels` hint.
// See this component's documentation for more information on how to specify the hint.
Labels *LabelsConfig `mapstructure:"labels"`

// Allows you to choose the entry format in the exporter.
// Deprecated: [v0.57.0] Only the JSON format will be supported in the future. If you rely on the
// "body" format and can't change to JSON, let us know before v0.59.0 by opening a GitHub issue
// and we'll work with you to find a solution.
Format *string `mapstructure:"format"`

// Tenant defines how to obtain the tenant ID
// Deprecated: [v0.57.0] use the attribute processor to add a `loki.tenant` hint.
// See this component's documentation for more information on how to specify the hint.
Tenant *Tenant `mapstructure:"tenant"`
}

func (c *Config) Validate() error {
Expand All @@ -58,45 +37,5 @@ func (c *Config) Validate() error {
if _, err := url.Parse(c.Endpoint); c.Endpoint == "" || err != nil {
return fmt.Errorf("\"endpoint\" must be a valid URL")
}

// further validation is needed only if we are in legacy mode
if !c.isLegacy() {
return nil
}

if c.Tenant != nil {
if c.Tenant.Source != "attributes" && c.Tenant.Source != "context" && c.Tenant.Source != "static" {
return fmt.Errorf("invalid tenant source, must be one of 'attributes', 'context', 'static', but is %s", c.Tenant.Source)
}

if c.TenantID != nil && *c.TenantID != "" {
return fmt.Errorf("both tenant_id and tenant were specified, use only 'tenant' instead")
}
}

if c.Labels != nil {
return c.Labels.validate()
}

return nil
}

func (c *Config) isLegacy() bool {
if c.Format != nil && *c.Format == "body" {
return true
}

if c.Labels != nil {
return true
}

if c.Tenant != nil {
return true
}

if c.TenantID != nil {
return true
}

return false
}
100 changes: 0 additions & 100 deletions exporter/lokiexporter/config_deprecated.go

This file was deleted.

76 changes: 0 additions & 76 deletions exporter/lokiexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,82 +93,6 @@ func TestLoadConfigNewExporter(t *testing.T) {
}
}

func TestIsLegacy(t *testing.T) {
testCases := []struct {
desc string
cfg *Config
outcome bool
}{
{
// the default mode for an empty config is the new logic
desc: "not legacy",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "https://loki.example.com",
},
},
outcome: false,
},
{
desc: "format is set to body",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "https://loki.example.com",
},
Format: stringp("body"),
},
outcome: true,
},
{
desc: "a label is specified",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "https://loki.example.com",
},
Labels: &LabelsConfig{
Attributes: map[string]string{"some_attribute": "some_value"},
},
},
outcome: true,
},
{
desc: "a tenant is specified",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "https://loki.example.com",
},
Tenant: &Tenant{
Source: "static",
Value: "acme",
},
},
outcome: true,
},
{
desc: "a tenant ID is specified",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "https://loki.example.com",
},
TenantID: stringp("acme"),
},
outcome: true,
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
assert.Equal(t, tC.outcome, tC.cfg.isLegacy())

// all configs from this table test are valid:
assert.NoError(t, tC.cfg.Validate())
})
}
}

func stringp(str string) *string {
return &str
}

func TestConfigValidate(t *testing.T) {
testCases := []struct {
desc string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"net/http"
"sync"

"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/pdata/plog"
Expand All @@ -32,23 +34,27 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/loki"
)

type nextLokiExporter struct {
const (
maxErrMsgLen = 1024
)

type lokiExporter struct {
config *Config
settings component.TelemetrySettings
client *http.Client
wg sync.WaitGroup
}

func newNextExporter(config *Config, settings component.TelemetrySettings) *nextLokiExporter {
func newExporter(config *Config, settings component.TelemetrySettings) *lokiExporter {
settings.Logger.Info("using the new Loki exporter")

return &nextLokiExporter{
return &lokiExporter{
config: config,
settings: settings,
}
}

func (l *nextLokiExporter) pushLogData(ctx context.Context, ld plog.Logs) error {
func (l *lokiExporter) pushLogData(ctx context.Context, ld plog.Logs) error {
requests := loki.LogsToLokiRequests(ld)

var errs error
Expand All @@ -60,7 +66,7 @@ func (l *nextLokiExporter) pushLogData(ctx context.Context, ld plog.Logs) error
return errs
}

func (l *nextLokiExporter) sendPushRequest(ctx context.Context, tenant string, request loki.PushRequest, ld plog.Logs) error {
func (l *lokiExporter) sendPushRequest(ctx context.Context, tenant string, request loki.PushRequest, ld plog.Logs) error {
pushReq := request.PushRequest
report := request.Report
if len(pushReq.Streams) == 0 {
Expand Down Expand Up @@ -123,7 +129,16 @@ func (l *nextLokiExporter) sendPushRequest(ctx context.Context, tenant string, r
return nil
}

func (l *nextLokiExporter) start(_ context.Context, host component.Host) (err error) {
func encode(pb proto.Message) ([]byte, error) {
buf, err := proto.Marshal(pb)
if err != nil {
return nil, err
}
buf = snappy.Encode(nil, buf)
return buf, nil
}

func (l *lokiExporter) start(_ context.Context, host component.Host) (err error) {
client, err := l.config.HTTPClientSettings.ToClient(host, l.settings)
if err != nil {
return err
Expand All @@ -134,7 +149,7 @@ func (l *nextLokiExporter) start(_ context.Context, host component.Host) (err er
return nil
}

func (l *nextLokiExporter) stop(context.Context) (err error) {
func (l *lokiExporter) stop(context.Context) (err error) {
l.wg.Wait()
return nil
}
Loading

0 comments on commit 795a094

Please sign in to comment.