Skip to content

Commit e095546

Browse files
Sumo Logic Syslog Processor (#1313)
* add sumologicsyslogprocessor Signed-off-by: Dominik Rosiek <[email protected]> Co-authored-by: Patryk Małek <[email protected]>
1 parent 3938c0d commit e095546

File tree

12 files changed

+1798
-0
lines changed

12 files changed

+1798
-0
lines changed

cmd/otelcontribcol/components.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import (
5555
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor"
5656
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/sourceprocessor"
5757
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/spanmetricsprocessor"
58+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/sumologicsyslogprocessor"
5859
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor"
5960
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsecscontainermetricsreceiver"
6061
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsxrayreceiver"
@@ -184,6 +185,7 @@ func components() (component.Factories, error) {
184185
routingprocessor.NewFactory(),
185186
tailsamplingprocessor.NewFactory(),
186187
spanmetricsprocessor.NewFactory(),
188+
sumologicsyslogprocessor.NewFactory(),
187189
}
188190
for _, pr := range factories.Processors {
189191
processors = append(processors, pr)

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/sour
214214

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

217+
replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/sumologicsyslogprocessor => ./processor/sumologicsyslogprocessor/
218+
217219
replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricstransformprocessor => ./processor/metricstransformprocessor/
218220

219221
replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor => ./processor/routingprocessor/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Sumo Logic Syslog Processor
2+
3+
Supported pipeline types: logs
4+
5+
The Sumo Logic Syslog processor can be used to create attribute with facility name
6+
based on facility code. Default facility name is `syslog`.
7+
8+
## Configuration
9+
10+
| Field | Default | Description |
11+
|---------------|----------|--------------------------------------------------------------------|
12+
| facility_attr | facility | The attribute name in which a facility name is going to be written |
13+
14+
## Examples
15+
16+
Following table shows example facility names which are extracted from log line
17+
18+
| log | facility |
19+
|---------------------------|---------------------|
20+
| <13> Example log | user-level messages |
21+
| <334> Another example log | syslog |
22+
| Plain text log | syslog |
23+
24+
## Configuration Example
25+
26+
```yaml
27+
processors:
28+
sumologic_syslog:
29+
facility_attr: testAttrName
30+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package sumologicsyslogprocessor
16+
17+
import (
18+
"go.opentelemetry.io/collector/config"
19+
)
20+
21+
// Config holds the configuration for tail-based sampling.
22+
type Config struct {
23+
*config.ProcessorSettings `mapstructure:"-"`
24+
25+
// FacilityAttr is the name of the attribute the facility name should be placed into.
26+
FacilityAttr string `mapstructure:"facility_attr"`
27+
}
28+
29+
const (
30+
defaultFacilityAttr = "facility"
31+
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package sumologicsyslogprocessor
16+
17+
import (
18+
"path"
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
"github.com/stretchr/testify/require"
23+
"go.opentelemetry.io/collector/component/componenttest"
24+
"go.opentelemetry.io/collector/config"
25+
"go.opentelemetry.io/collector/config/configtest"
26+
)
27+
28+
func TestLoadConfig(t *testing.T) {
29+
factories, err := componenttest.NopFactories()
30+
require.NoError(t, err)
31+
32+
factory := NewFactory()
33+
factories.Processors[factory.Type()] = factory
34+
35+
cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "sumologic_syslog_config.yaml"), factories)
36+
require.NoError(t, err)
37+
require.NotNil(t, cfg)
38+
39+
assert.Equal(t, cfg.Processors["sumologic_syslog"],
40+
&Config{
41+
ProcessorSettings: config.NewProcessorSettings(typeStr),
42+
FacilityAttr: "testAttrName",
43+
})
44+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package sumologicsyslogprocessor
16+
17+
import (
18+
"context"
19+
20+
"go.opentelemetry.io/collector/component"
21+
"go.opentelemetry.io/collector/config"
22+
"go.opentelemetry.io/collector/consumer"
23+
"go.opentelemetry.io/collector/processor/processorhelper"
24+
)
25+
26+
const (
27+
// The value of "type" Tail Sampling in configuration.
28+
typeStr = "sumologic_syslog"
29+
)
30+
31+
var processorCapabilities = component.ProcessorCapabilities{MutatesConsumedData: true}
32+
33+
// NewFactory returns a new factory for the Tail Sampling processor.
34+
func NewFactory() component.ProcessorFactory {
35+
return processorhelper.NewFactory(
36+
typeStr,
37+
createDefaultConfig,
38+
processorhelper.WithLogs(createLogProcessor))
39+
}
40+
41+
func createDefaultConfig() config.Processor {
42+
return &Config{
43+
ProcessorSettings: config.NewProcessorSettings(typeStr),
44+
FacilityAttr: defaultFacilityAttr,
45+
}
46+
}
47+
48+
func createLogProcessor(
49+
_ context.Context,
50+
params component.ProcessorCreateParams,
51+
cfg config.Processor,
52+
nextConsumer consumer.Logs,
53+
) (component.LogsProcessor, error) {
54+
tCfg := cfg.(*Config)
55+
56+
return processorhelper.NewLogsProcessor(
57+
cfg,
58+
nextConsumer,
59+
newSumologicSyslogProcessor(tCfg),
60+
processorhelper.WithCapabilities(processorCapabilities))
61+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package sumologicsyslogprocessor
16+
17+
import (
18+
"context"
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
"go.opentelemetry.io/collector/component"
23+
"go.opentelemetry.io/collector/config/configcheck"
24+
"go.opentelemetry.io/collector/consumer/consumertest"
25+
"go.uber.org/zap"
26+
)
27+
28+
func TestCreateDefaultConfig(t *testing.T) {
29+
cfg := createDefaultConfig()
30+
assert.NotNil(t, cfg, "failed to create default config")
31+
assert.NoError(t, configcheck.ValidateConfig(cfg))
32+
}
33+
34+
func TestLogProcessor(t *testing.T) {
35+
factory := NewFactory()
36+
37+
cfg := factory.CreateDefaultConfig().(*Config)
38+
// Manually set required fields
39+
cfg.FacilityAttr = "testAttrName"
40+
41+
params := component.ProcessorCreateParams{Logger: zap.NewNop()}
42+
lp, err := factory.CreateLogsProcessor(context.Background(), params, cfg, consumertest.NewNop())
43+
assert.NotNil(t, lp)
44+
assert.NoError(t, err, "cannot create log processor")
45+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module github.com/open-telemetry/opentelemetry-collector-contrib/processor/sumologicsyslogprocessor
2+
3+
go 1.14
4+
5+
require (
6+
github.com/stretchr/testify v1.7.0
7+
go.opentelemetry.io/collector v0.25.0
8+
go.uber.org/zap v1.16.0 // indirect
9+
)

0 commit comments

Comments
 (0)