Skip to content

Commit

Permalink
Sumo Logic Syslog Processor (#1313)
Browse files Browse the repository at this point in the history
* add sumologicsyslogprocessor

Signed-off-by: Dominik Rosiek <[email protected]>
Co-authored-by: Patryk Małek <[email protected]>
  • Loading branch information
2 people authored and Dominik Rosiek committed May 31, 2021
1 parent 3938c0d commit c20d589
Show file tree
Hide file tree
Showing 13 changed files with 1,800 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/sourceprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/spanmetricsprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/sumologicsyslogprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsecscontainermetricsreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsxrayreceiver"
Expand Down Expand Up @@ -184,6 +185,7 @@ func components() (component.Factories, error) {
routingprocessor.NewFactory(),
tailsamplingprocessor.NewFactory(),
spanmetricsprocessor.NewFactory(),
sumologicsyslogprocessor.NewFactory(),
}
for _, pr := range factories.Processors {
processors = append(processors, pr)
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/processor/sourceprocessor v0.0.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/spanmetricsprocessor v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/processor/sumologicsyslogprocessor v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsecscontainermetricsreceiver v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsxrayreceiver v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -214,6 +215,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/sour

replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor => ./processor/resourcedetectionprocessor/

replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/sumologicsyslogprocessor => ./processor/sumologicsyslogprocessor/

replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricstransformprocessor => ./processor/metricstransformprocessor/

replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor => ./processor/routingprocessor/
Expand Down
1 change: 1 addition & 0 deletions processor/sumologicsyslogprocessor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
30 changes: 30 additions & 0 deletions processor/sumologicsyslogprocessor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Sumo Logic Syslog Processor

Supported pipeline types: logs

The Sumo Logic Syslog processor can be used to create attribute with facility name
based on facility code. Default facility name is `syslog`.

## Configuration

| Field | Default | Description |
|---------------|----------|--------------------------------------------------------------------|
| facility_attr | facility | The attribute name in which a facility name is going to be written |

## Examples

Following table shows example facility names which are extracted from log line

| log | facility |
|---------------------------|---------------------|
| <13> Example log | user-level messages |
| <334> Another example log | syslog |
| Plain text log | syslog |

## Configuration Example

```yaml
processors:
sumologic_syslog:
facility_attr: testAttrName
```
31 changes: 31 additions & 0 deletions processor/sumologicsyslogprocessor/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright The 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 sumologicsyslogprocessor

import (
"go.opentelemetry.io/collector/config"
)

// Config holds the configuration for tail-based sampling.
type Config struct {
*config.ProcessorSettings `mapstructure:"-"`

// FacilityAttr is the name of the attribute the facility name should be placed into.
FacilityAttr string `mapstructure:"facility_attr"`
}

const (
defaultFacilityAttr = "facility"
)
44 changes: 44 additions & 0 deletions processor/sumologicsyslogprocessor/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright The 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 sumologicsyslogprocessor

import (
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configtest"
)

func TestLoadConfig(t *testing.T) {
factories, err := componenttest.NopFactories()
require.NoError(t, err)

factory := NewFactory()
factories.Processors[factory.Type()] = factory

cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "sumologic_syslog_config.yaml"), factories)
require.NoError(t, err)
require.NotNil(t, cfg)

assert.Equal(t, cfg.Processors["sumologic_syslog"],
&Config{
ProcessorSettings: config.NewProcessorSettings(typeStr),
FacilityAttr: "testAttrName",
})
}
61 changes: 61 additions & 0 deletions processor/sumologicsyslogprocessor/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright The 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 sumologicsyslogprocessor

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor/processorhelper"
)

const (
// The value of "type" Tail Sampling in configuration.
typeStr = "sumologic_syslog"
)

var processorCapabilities = component.ProcessorCapabilities{MutatesConsumedData: true}

// NewFactory returns a new factory for the Tail Sampling processor.
func NewFactory() component.ProcessorFactory {
return processorhelper.NewFactory(
typeStr,
createDefaultConfig,
processorhelper.WithLogs(createLogProcessor))
}

func createDefaultConfig() config.Processor {
return &Config{
ProcessorSettings: config.NewProcessorSettings(typeStr),
FacilityAttr: defaultFacilityAttr,
}
}

func createLogProcessor(
_ context.Context,
params component.ProcessorCreateParams,
cfg config.Processor,
nextConsumer consumer.Logs,
) (component.LogsProcessor, error) {
tCfg := cfg.(*Config)

return processorhelper.NewLogsProcessor(
cfg,
nextConsumer,
newSumologicSyslogProcessor(tCfg),
processorhelper.WithCapabilities(processorCapabilities))
}
45 changes: 45 additions & 0 deletions processor/sumologicsyslogprocessor/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright The 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 sumologicsyslogprocessor

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.uber.org/zap"
)

func TestCreateDefaultConfig(t *testing.T) {
cfg := createDefaultConfig()
assert.NotNil(t, cfg, "failed to create default config")
assert.NoError(t, configcheck.ValidateConfig(cfg))
}

func TestLogProcessor(t *testing.T) {
factory := NewFactory()

cfg := factory.CreateDefaultConfig().(*Config)
// Manually set required fields
cfg.FacilityAttr = "testAttrName"

params := component.ProcessorCreateParams{Logger: zap.NewNop()}
lp, err := factory.CreateLogsProcessor(context.Background(), params, cfg, consumertest.NewNop())
assert.NotNil(t, lp)
assert.NoError(t, err, "cannot create log processor")
}
9 changes: 9 additions & 0 deletions processor/sumologicsyslogprocessor/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/processor/sumologicsyslogprocessor

go 1.14

require (
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/collector v0.25.0
go.uber.org/zap v1.16.0 // indirect
)
Loading

0 comments on commit c20d589

Please sign in to comment.