forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add sumologicsyslogprocessor Signed-off-by: Dominik Rosiek <[email protected]> Co-authored-by: Patryk Małek <[email protected]>
- Loading branch information
1 parent
3938c0d
commit c20d589
Showing
13 changed files
with
1,800 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.