Skip to content

Commit

Permalink
[logs_processors] Add support for lookup processors
Browse files Browse the repository at this point in the history
  • Loading branch information
blemale committed Nov 20, 2019
1 parent 557151e commit 44bf87a
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 3 deletions.
93 changes: 93 additions & 0 deletions datadog-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11763,6 +11763,99 @@ func (l *LogStreamDefinition) SetType(v string) {
l.Type = &v
}

// GetDefaultLookup returns the DefaultLookup field if non-nil, zero value otherwise.
func (l *LookupProcessor) GetDefaultLookup() string {
if l == nil || l.DefaultLookup == nil {
return ""
}
return *l.DefaultLookup
}

// GetDefaultLookupOk returns a tuple with the DefaultLookup field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (l *LookupProcessor) GetDefaultLookupOk() (string, bool) {
if l == nil || l.DefaultLookup == nil {
return "", false
}
return *l.DefaultLookup, true
}

// HasDefaultLookup returns a boolean if a field has been set.
func (l *LookupProcessor) HasDefaultLookup() bool {
if l != nil && l.DefaultLookup != nil {
return true
}

return false
}

// SetDefaultLookup allocates a new l.DefaultLookup and returns the pointer to it.
func (l *LookupProcessor) SetDefaultLookup(v string) {
l.DefaultLookup = &v
}

// GetSource returns the Source field if non-nil, zero value otherwise.
func (l *LookupProcessor) GetSource() string {
if l == nil || l.Source == nil {
return ""
}
return *l.Source
}

// GetSourceOk returns a tuple with the Source field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (l *LookupProcessor) GetSourceOk() (string, bool) {
if l == nil || l.Source == nil {
return "", false
}
return *l.Source, true
}

// HasSource returns a boolean if a field has been set.
func (l *LookupProcessor) HasSource() bool {
if l != nil && l.Source != nil {
return true
}

return false
}

// SetSource allocates a new l.Source and returns the pointer to it.
func (l *LookupProcessor) SetSource(v string) {
l.Source = &v
}

// GetTarget returns the Target field if non-nil, zero value otherwise.
func (l *LookupProcessor) GetTarget() string {
if l == nil || l.Target == nil {
return ""
}
return *l.Target
}

// GetTargetOk returns a tuple with the Target field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (l *LookupProcessor) GetTargetOk() (string, bool) {
if l == nil || l.Target == nil {
return "", false
}
return *l.Target, true
}

// HasTarget returns a boolean if a field has been set.
func (l *LookupProcessor) HasTarget() bool {
if l != nil && l.Target != nil {
return true
}

return false
}

// SetTarget allocates a new l.Target and returns the pointer to it.
func (l *LookupProcessor) SetTarget(v string) {
l.Target = &v
}

// GetColorPreference returns the ColorPreference field if non-nil, zero value otherwise.
func (m *ManageStatusDefinition) GetColorPreference() string {
if m == nil || m.ColorPreference == nil {
Expand Down
15 changes: 13 additions & 2 deletions integration/logs_pipelines_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package integration

import (
"github.com/stretchr/testify/assert"
"github.com/zorkian/go-datadog-api"
"log"
"testing"

"github.com/stretchr/testify/assert"
"github.com/zorkian/go-datadog-api"
)

func TestLogsPipelineCrud(t *testing.T) {
Expand Down Expand Up @@ -151,6 +152,16 @@ func TestLogsPipelineCrud(t *testing.T) {
Sources: []string{"source1", "source2"},
Target: datadog.String("target"),
},
}, {
Name: datadog.String("lookup processor test"),
IsEnabled: datadog.Bool(false),
Type: datadog.String("lookup-processor"),
Definition: datadog.LookupProcessor{
Source: datadog.String("source"),
Target: datadog.String("target"),
LookupTable: []string{"key1,value1", "key2,value2"},
DefaultLookup: datadog.String("default"),
},
},
},
})
Expand Down
13 changes: 12 additions & 1 deletion logs_pipelines_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package datadog

import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

func TestLogsPipelineGetAll(t *testing.T) {
Expand Down Expand Up @@ -175,6 +176,16 @@ var expectedPipeline = &LogsPipeline{
Sources: []string{"source1", "source2"},
Target: String("target"),
},
}, {
Name: String("lookup processor test"),
IsEnabled: Bool(false),
Type: String("lookup-processor"),
Definition: LookupProcessor{
Source: String("source"),
Target: String("target"),
LookupTable: []string{"key1,value1", "key2,value2"},
DefaultLookup: String("default"),
},
},
},
}
15 changes: 15 additions & 0 deletions logs_processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
DateRemapperType = "date-remapper"
GeoIPParserType = "geo-ip-parser"
GrokParserType = "grok-parser"
LookupProcessorType = "lookup-processor"
MessageRemapperType = "message-remapper"
NestedPipelineType = "pipeline"
ServiceRemapperType = "service-remapper"
Expand Down Expand Up @@ -93,6 +94,14 @@ type GrokRule struct {
MatchRules *string `json:"match_rules"`
}

// LookupProcessor represents the lookup processor from config API.
type LookupProcessor struct {
Source *string `json:"source"`
Target *string `json:"target"`
LookupTable []string `json:"lookup_table"`
DefaultLookup *string `json:"default_lookup"`
}

// NestedPipeline represents the pipeline as processor from config API.
type NestedPipeline struct {
Filter *FilterConfiguration `json:"filter"`
Expand Down Expand Up @@ -200,6 +209,12 @@ func (processor *LogsProcessor) UnmarshalJSON(data []byte) error {
return err
}
processor.Definition = grokParser
case LookupProcessorType:
var lookupProcessor LookupProcessor
if err := json.Unmarshal(data, &lookupProcessor); err != nil {
return err
}
processor.Definition = lookupProcessor
case NestedPipelineType:
var nestedPipeline NestedPipeline
if err := json.Unmarshal(data, &nestedPipeline); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures/logs/pipeline_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@
"sources": ["source1", "source2"],
"target": "target",
"type": "geo-ip-parser"
},
{
"name": "lookup processor test",
"is_enabled": false,
"source": "source",
"target": "target",
"lookup_table": ["key1,value1", "key2,value2"],
"default_lookup": "default",
"type": "lookup-processor"
}
]
}

0 comments on commit 44bf87a

Please sign in to comment.