Skip to content

Commit

Permalink
feature: add datadog_output type
Browse files Browse the repository at this point in the history
Signed-off-by: Bojan <dbojan@gmail.com>
  • Loading branch information
bojand committed Sep 29, 2021
1 parent c91a044 commit b076633
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/fluentbitoperator/v1alpha2/output_types.go
Expand Up @@ -60,6 +60,8 @@ type OutputSpec struct {
Loki *output.Loki `json:"loki,omitempty"`
// Syslog defines Syslog Output configuration.
Syslog *output.Syslog `json:"syslog,omitempty"`
// DataDog defines DataDog Output configuration.
DataDog *output.DataDog `json:"datadog,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions api/fluentbitoperator/v1alpha2/plugins/output/datadog_types.go
@@ -0,0 +1,95 @@
package output

import (
"fmt"

"kubesphere.io/fluentbit-operator/api/fluentbitoperator/v1alpha2/plugins"
"kubesphere.io/fluentbit-operator/api/fluentbitoperator/v1alpha2/plugins/params"
)

// +kubebuilder:object:generate:=true

// DataDog output plugin allows you to ingest your logs into Datadog.
type DataDog struct {
// Host is the Datadog server where you are sending your logs.
Host string `json:"host,omitempty"`
// TLS controls whether to use end-to-end security communications security protocol.
// Datadog recommends setting this to on.
TLS *bool `json:"tls,omitempty"`
// Compress the payload in GZIP format.
// Datadog supports and recommends setting this to gzip.
Compress string `json:"compress,omitempty"`
// Your Datadog API key.
APIKey string `json:"apikey,omitempty"`
// Specify an HTTP Proxy.
Proxy string `json:"proxy,omitempty"`
// To activate the remapping, specify configuration flag provider.
Provider string `json:"provider,omitempty"`
// Date key name for output.
JSONDateKey string `json:"json_date_key,omitempty"`
// If enabled, a tag is appended to output. The key name is used tag_key property.
IncludeTagKey *bool `json:"include_tag_key,omitempty"`
// The key name of tag. If include_tag_key is false, This property is ignored.
TagKey string `json:"tag_key,omitempty"`
// The human readable name for your service generating the logs.
Service string `json:"dd_service,omitempty"`
// A human readable name for the underlying technology of your service.
Source string `json:"dd_source,omitempty"`
// The tags you want to assign to your logs in Datadog.
Tags string `json:"dd_tags,omitempty"`
// By default, the plugin searches for the key 'log' and remap the value to the key 'message'. If the property is set, the plugin will search the property name key.
MessageKey string `json:"dd_message_key,omitempty"`

// *plugins.HTTP `json:"tls,omitempty"`
}

func (_ *DataDog) Name() string {
return "datadog"
}

// implement Section() method
func (s *DataDog) Params(sl plugins.SecretLoader) (*params.KVs, error) {
kvs := params.NewKVs()

if s.Host != "" {
kvs.Insert("Host", s.Host)
}
if s.TLS != nil {
kvs.Insert("TLS", fmt.Sprint(*s.TLS))
}
if s.Compress != "" {
kvs.Insert("compress", s.Compress)
}
if s.APIKey != "" {
kvs.Insert("apikey", s.APIKey)
}
if s.Proxy != "" {
kvs.Insert("proxy", s.Proxy)
}
if s.Provider != "" {
kvs.Insert("provider", s.Provider)
}
if s.JSONDateKey != "" {
kvs.Insert("json_date_key", s.JSONDateKey)
}
if s.IncludeTagKey != nil {
kvs.Insert("include_tag_key", fmt.Sprint(*s.IncludeTagKey))
}
if s.TagKey != "" {
kvs.Insert("tag_key", s.TagKey)
}
if s.Service != "" {
kvs.Insert("dd_service", s.Service)
}
if s.Source != "" {
kvs.Insert("dd_source", s.Source)
}
if s.Tags != "" {
kvs.Insert("dd_tags", s.Tags)
}
if s.MessageKey != "" {
kvs.Insert("dd_message_key", s.MessageKey)
}

return kvs, nil
}
@@ -0,0 +1,51 @@
package output

import (
"testing"

. "github.com/onsi/gomega"
"kubesphere.io/fluentbit-operator/api/fluentbitoperator/v1alpha2/plugins"
"kubesphere.io/fluentbit-operator/api/fluentbitoperator/v1alpha2/plugins/params"
)

func TestOutput_DataDog_Params(t *testing.T) {
g := NewGomegaWithT(t)

sl := plugins.NewSecretLoader(nil, "test namespace", nil)

dd := DataDog{
Host: "http-intake.logs.datadoghq.com",
APIKey: "1234apikey",
TLS: ptrBool(true),
Compress: "gzip",
Service: "service_name",
Source: "app_name",
Tags: "foo:bar",
MessageKey: "message",
JSONDateKey: "timestamp",
IncludeTagKey: ptrBool(true),
TagKey: "tagkey",
}

expected := params.NewKVs()
expected.Insert("Host", "http-intake.logs.datadoghq.com")
expected.Insert("TLS", "true")
expected.Insert("compress", "gzip")
expected.Insert("apikey", "1234apikey")
expected.Insert("json_date_key", "timestamp")
expected.Insert("include_tag_key", "true")
expected.Insert("tag_key", "tagkey")
expected.Insert("dd_service", "service_name")
expected.Insert("dd_source", "app_name")
expected.Insert("dd_tags", "foo:bar")
expected.Insert("dd_message_key", "message")

kvs, err := dd.Params(sl)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(kvs).To(Equal(expected))

}

func ptrBool(v bool) *bool {
return &v
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api/fluentbitoperator/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions config/crd/bases/logging.kubesphere.io_outputs.yaml
Expand Up @@ -40,6 +40,59 @@ spec:
description: A user friendly alias name for this output plugin. Used
in metrics for distinction of each configured output.
type: string
datadog:
description: DataDog defines DataDog Output configuration.
properties:
apikey:
description: Your Datadog API key.
type: string
compress:
description: Compress the payload in GZIP format. Datadog supports
and recommends setting this to gzip.
type: string
dd_message_key:
description: By default, the plugin searches for the key 'log'
and remap the value to the key 'message'. If the property is
set, the plugin will search the property name key.
type: string
dd_service:
description: The human readable name for your service generating
the logs.
type: string
dd_source:
description: A human readable name for the underlying technology
of your service.
type: string
dd_tags:
description: The tags you want to assign to your logs in Datadog.
type: string
host:
description: Host is the Datadog server where you are sending
your logs.
type: string
include_tag_key:
description: If enabled, a tag is appended to output. The key
name is used tag_key property.
type: boolean
json_date_key:
description: Date key name for output.
type: string
provider:
description: To activate the remapping, specify configuration
flag provider.
type: string
proxy:
description: Specify an HTTP Proxy.
type: string
tag_key:
description: The key name of tag. If include_tag_key is false,
This property is ignored.
type: string
tls:
description: TLS controls whether to use end-to-end security communications
security protocol. Datadog recommends setting this to on.
type: boolean
type: object
es:
description: Elasticsearch defines Elasticsearch Output configuration.
properties:
Expand Down
53 changes: 53 additions & 0 deletions manifests/setup/fluentbit-operator-crd.yaml
Expand Up @@ -3399,6 +3399,59 @@ spec:
description: A user friendly alias name for this output plugin. Used
in metrics for distinction of each configured output.
type: string
datadog:
description: DataDog defines DataDog Output configuration.
properties:
apikey:
description: Your Datadog API key.
type: string
compress:
description: Compress the payload in GZIP format. Datadog supports
and recommends setting this to gzip.
type: string
dd_message_key:
description: By default, the plugin searches for the key 'log'
and remap the value to the key 'message'. If the property is
set, the plugin will search the property name key.
type: string
dd_service:
description: The human readable name for your service generating
the logs.
type: string
dd_source:
description: A human readable name for the underlying technology
of your service.
type: string
dd_tags:
description: The tags you want to assign to your logs in Datadog.
type: string
host:
description: Host is the Datadog server where you are sending
your logs.
type: string
include_tag_key:
description: If enabled, a tag is appended to output. The key
name is used tag_key property.
type: boolean
json_date_key:
description: Date key name for output.
type: string
provider:
description: To activate the remapping, specify configuration
flag provider.
type: string
proxy:
description: Specify an HTTP Proxy.
type: string
tag_key:
description: The key name of tag. If include_tag_key is false,
This property is ignored.
type: string
tls:
description: TLS controls whether to use end-to-end security communications
security protocol. Datadog recommends setting this to on.
type: boolean
type: object
es:
description: Elasticsearch defines Elasticsearch Output configuration.
properties:
Expand Down

0 comments on commit b076633

Please sign in to comment.