Skip to content

Commit 1fc8d94

Browse files
committed
Updated functionality so that sourceType now requires payloadKey to be defined. Docs updated. Added api validation, e2e and functional tests.
1 parent f0faae7 commit 1fc8d94

15 files changed

Lines changed: 366 additions & 144 deletions

api/observability/v1/output_types.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,7 @@ type SplunkAuthentication struct {
12511251

12521252
// Splunk Deliver log data to Splunk’s HTTP Event Collector
12531253
// Provides optional extra properties for `type: splunk_hec` ('splunk_hec_logs' after Vector 0.23
1254+
// +kubebuilder:validation:XValidation:rule="!has(self.sourceType) || has(self.payloadKey)",message="sourceType can only be set when payloadKey is defined"
12541255
type Splunk struct {
12551256
// Authentication sets credentials for authenticating the requests.
12561257
//
@@ -1320,19 +1321,30 @@ type Splunk struct {
13201321
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Source",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
13211322
Source string `json:"source,omitempty"`
13221323

1323-
// SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
1324-
// If not specified, the Splunk source type used is `_json` but may be overridden when using `payloadKey`, depending on the structure of the final event payload.
1324+
// SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
1325+
//
1326+
// WARNING: The administrator is responsible for configuring the pipeline so the source type matches the log entry. The collector makes no effort or validation to ensure they match.
1327+
//
1328+
// If SourceType is not specified, the source type used is `_json`. If using PayloadKey without SourceType, the source type used will be either `_json` or `generic_single_line`, depending on the structure of the final event payload.
13251329
// Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
13261330
//
1331+
// The SourceType can be a combination of static and dynamic values consisting of field paths followed by `||` followed by another field path or a static value.
1332+
// A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
1333+
//
1334+
// Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
1335+
//
13271336
// Examples:
13281337
//
1329-
// 1. "access_combined"
1338+
// 1. "log4j"
13301339
//
1331-
// 2. "log4j"
1340+
// 2. foo-{.bar||"none"}
13321341
//
1333-
// 3. "my:custom:sourcetype"
1342+
// 3. {.foo||.bar||"missing"}
1343+
//
1344+
// 4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
13341345
//
13351346
// +kubebuilder:validation:Optional
1347+
// +kubebuilder:validation:Pattern:=`^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$`
13361348
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="SourceType",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
13371349
SourceType string `json:"sourceType,omitempty"`
13381350

bundle/manifests/cluster-logging.clusterserviceversion.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,17 +1917,27 @@ spec:
19171917
x-descriptors:
19181918
- urn:alm:descriptor:com.tectonic.ui:text
19191919
- description: |-
1920-
SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
1921-
If not specified, the Splunk source type used is `_json` but may be overridden when using `payloadKey`, depending on the structure of the final event payload.
1920+
SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
1921+
1922+
WARNING: The administrator is responsible for configuring the pipeline so the source type matches the log entry. The collector makes no effort or validation to ensure they match.
1923+
1924+
If SourceType is not specified, the source type used is `_json`. If using PayloadKey without SourceType, the source type used will be either `_json` or `generic_single_line`, depending on the structure of the final event payload.
19221925
Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
19231926
1927+
The SourceType can be a combination of static and dynamic values consisting of field paths followed by `||` followed by another field path or a static value.
1928+
A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
1929+
1930+
Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
1931+
19241932
Examples:
19251933
1926-
1. "access_combined"
1934+
1. "log4j"
1935+
1936+
2. foo-{.bar||"none"}
19271937
1928-
2. "log4j"
1938+
3. {.foo||.bar||"missing"}
19291939
1930-
3. "my:custom:sourcetype"
1940+
4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
19311941
displayName: SourceType
19321942
path: outputs[0].splunk.sourceType
19331943
x-descriptors:

bundle/manifests/observability.openshift.io_clusterlogforwarders.yaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,17 +3855,28 @@ spec:
38553855
type: string
38563856
sourceType:
38573857
description: |-
3858-
SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
3859-
If not specified, the Splunk source type used is `_json` but may be overridden when using `payloadKey`, depending on the structure of the final event payload.
3858+
SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
3859+
3860+
WARNING: The administrator is responsible for configuring the pipeline so the source type matches the log entry. The collector makes no effort or validation to ensure they match.
3861+
3862+
If SourceType is not specified, the source type used is `_json`. If using PayloadKey without SourceType, the source type used will be either `_json` or `generic_single_line`, depending on the structure of the final event payload.
38603863
Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
38613864
3865+
The SourceType can be a combination of static and dynamic values consisting of field paths followed by `||` followed by another field path or a static value.
3866+
A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
3867+
3868+
Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
3869+
38623870
Examples:
38633871
3864-
1. "access_combined"
3872+
1. "log4j"
3873+
3874+
2. foo-{.bar||"none"}
38653875
3866-
2. "log4j"
3876+
3. {.foo||.bar||"missing"}
38673877
3868-
3. "my:custom:sourcetype"
3878+
4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
3879+
pattern: ^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$
38693880
type: string
38703881
tuning:
38713882
description: Tuning specs tuning for the output
@@ -3920,6 +3931,9 @@ spec:
39203931
- authentication
39213932
- url
39223933
type: object
3934+
x-kubernetes-validations:
3935+
- message: sourceType can only be set when payloadKey is defined
3936+
rule: '!has(self.sourceType) || has(self.payloadKey)'
39233937
syslog:
39243938
description: Syslog configures forwarding log events to a receiver
39253939
using the syslog protocol

config/crd/bases/observability.openshift.io_clusterlogforwarders.yaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,17 +3855,28 @@ spec:
38553855
type: string
38563856
sourceType:
38573857
description: |-
3858-
SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
3859-
If not specified, the Splunk source type used is `_json` but may be overridden when using `payloadKey`, depending on the structure of the final event payload.
3858+
SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
3859+
3860+
WARNING: The administrator is responsible for configuring the pipeline so the source type matches the log entry. The collector makes no effort or validation to ensure they match.
3861+
3862+
If SourceType is not specified, the source type used is `_json`. If using PayloadKey without SourceType, the source type used will be either `_json` or `generic_single_line`, depending on the structure of the final event payload.
38603863
Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
38613864
3865+
The SourceType can be a combination of static and dynamic values consisting of field paths followed by `||` followed by another field path or a static value.
3866+
A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
3867+
3868+
Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
3869+
38623870
Examples:
38633871
3864-
1. "access_combined"
3872+
1. "log4j"
3873+
3874+
2. foo-{.bar||"none"}
38653875
3866-
2. "log4j"
3876+
3. {.foo||.bar||"missing"}
38673877
3868-
3. "my:custom:sourcetype"
3878+
4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
3879+
pattern: ^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$
38693880
type: string
38703881
tuning:
38713882
description: Tuning specs tuning for the output
@@ -3920,6 +3931,9 @@ spec:
39203931
- authentication
39213932
- url
39223933
type: object
3934+
x-kubernetes-validations:
3935+
- message: sourceType can only be set when payloadKey is defined
3936+
rule: '!has(self.sourceType) || has(self.payloadKey)'
39233937
syslog:
39243938
description: Syslog configures forwarding log events to a receiver
39253939
using the syslog protocol

config/manifests/bases/cluster-logging.clusterserviceversion.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,17 +1840,27 @@ spec:
18401840
x-descriptors:
18411841
- urn:alm:descriptor:com.tectonic.ui:text
18421842
- description: |-
1843-
SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
1844-
If not specified, the Splunk source type used is `_json` but may be overridden when using `payloadKey`, depending on the structure of the final event payload.
1843+
SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
1844+
1845+
WARNING: The administrator is responsible for configuring the pipeline so the source type matches the log entry. The collector makes no effort or validation to ensure they match.
1846+
1847+
If SourceType is not specified, the source type used is `_json`. If using PayloadKey without SourceType, the source type used will be either `_json` or `generic_single_line`, depending on the structure of the final event payload.
18451848
Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
18461849
1850+
The SourceType can be a combination of static and dynamic values consisting of field paths followed by `||` followed by another field path or a static value.
1851+
A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
1852+
1853+
Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
1854+
18471855
Examples:
18481856
1849-
1. "access_combined"
1857+
1. "log4j"
1858+
1859+
2. foo-{.bar||"none"}
18501860
1851-
2. "log4j"
1861+
3. {.foo||.bar||"missing"}
18521862
1853-
3. "my:custom:sourcetype"
1863+
4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
18541864
displayName: SourceType
18551865
path: outputs[0].splunk.sourceType
18561866
x-descriptors:

docs/features/logforwarding/outputs/splunk-forwarding.adoc

Lines changed: 63 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ spec:
5454
2. `url`: The base URL of the Splunk instance.
5555
3. `index`: Optional. The name of the index to send events to. If not specified, the default index defined within Splunk is used. This supports template syntax to allow dynamic per-event values.
5656
4. `source`: Optional. The source of events sent to this sink. This supports template syntax to allow dynamic per-event values.
57-
5. `sourceType`: Optional. Can be used to specify a pretrained or custom sourcetype in Splunk. If not specified it will default to `_json` and be detected by .payloadkey.
57+
5. `sourceType`: Optional. Can be used to specify a https://help.splunk.com/en/splunk-enterprise/get-started/get-data-in/10.2/configure-source-types/list-of-pretrained-source-types[pretrained] or custom sourcetype in Splunk when the payloadKey is additionally defined. If not specified, it will default to `_json`.
5858
6. `indexedFields`: Optional. Fields to be added to Splunk index.
5959
7. `payloadKey`: Optional. Specifies record field to use as payload.
6060
8. `compression`: Optional. Compression configuration, available to are: `none`, `gzip`. Default is `none`.
@@ -67,88 +67,76 @@ following Cluster Log Forwarder's conventions.
6767
=== `sourceType`
6868
In Splunk, the source type is used to define how incoming data should be parsed, interpreted, and categorised. Splunk includes many built-in source types and also allows for custom source types to be defined. The `sourceType` field should reference a source type configured in Splunk.
6969
70-
If not specified, the Splunk source type used is `_json` but may be overridden when using `payloadKey`, depending on the structure of the final event payload.
70+
This field must be used in combination with `payloadKey`.
7171
72-
An example of a use case for this field is where a custom Splunk source type has been created to interpret particular log message content where key/value pairs are extracted and transformed into Splunk fields for use with dashboards.
72+
If `sourceType` is not specified, the source type used is `_json`. If using `payloadKey` without `sourceType`, the source type used will be either `_json` or `generic_single_line`, depending on the structure of the final event payload.
7373
74-
Here is an example of a CLF where log events for an app are forwarded to a Splunk output sink with a user-defined source type :
74+
WARNING: The administrator is responsible for configuring the pipeline so the source type matches the log entry. The collector makes no effort or validation to ensure they match.
7575
76-
```
76+
The `sourceType` field can be defined in the CLF as a templated field to get its value from the stuctured log event, such as a pod label.
77+
78+
Below is an example of a pod which defines the source type to use in a label named `splunk_sourcetype`:
79+
80+
[source,yaml]
81+
----
82+
apiVersion: v1
83+
kind: Pod
84+
metadata:
85+
name: myapp
86+
labels:
87+
app: myapp
88+
splunk_sourcetype: log4j
7789
spec:
78-
inputs:
79-
- application:
80-
includes:
81-
- container: myapp
82-
namespace: my-app-*
83-
name: myapp
84-
type: application
85-
outputs:
86-
- name: splunk-myapp
87-
splunk:
88-
authentication:
89-
token:
90-
key: hecToken
91-
secretName: splunk-myapp
92-
sourceType: 'myapp:sourcetype'
93-
url: 'https://splunk.customer.com:8088'
94-
type: splunk
95-
pipelines:
90+
containers:
9691
- name: myapp
97-
inputRefs:
98-
- myapp
99-
outputRefs:
100-
- splunk-myapp
101-
```
102-
103-
If a source type needs to be referenced for a particular application's log events, but is not appropriate for others, be sure to structure the ClusterLogFowarder so that it does not misrepresent the format of log events by using a single Splunk output sink.
92+
image: myapp:latest
93+
ports:
94+
- containerPort: 80
95+
----
10496
105-
Here is an example of a CLF where cluster-wide general app log events are forwarded to a Splunk output sink using the default source type of `_json`, and log events for an app are forwarded to a different Splunk output sink with a user-defined source type :
97+
Below is an example of the CLF which sets `payloadKey` to `.message` and uses a template to set the `sourceType` to match the `splunk_sourcetype` pod label. If the label does not exist, the source type of "generic_single_line" will be used, which is a built-in Splunk source type.
10698
107-
```
99+
[source,yaml]
100+
----
101+
apiVersion: observability.openshift.io/v1
102+
kind: ClusterLogForwarder
103+
metadata:
104+
name: collector
105+
namespace: openshift-logging
108106
spec:
107+
collector:
108+
resources:
109+
limits:
110+
cpu: "6"
111+
memory: 2Gi
112+
requests:
113+
cpu: 500m
114+
memory: 64Mi
109115
inputs:
110-
- name: application-general
111-
application:
112-
excludes:
113-
- container: myapp
114-
namespace: my-app-*
115-
type: application
116-
- name: application-myapp
117-
application:
118-
includes:
119-
- container: myapp
120-
namespace: my-app-*
121-
type: application
116+
- application: {}
117+
name: application
118+
type: application
119+
managementState: Managed
122120
outputs:
123-
- name: splunk-application-general
124-
splunk:
125-
authentication:
126-
token:
127-
key: hecToken
128-
secretName: splunk-application-general
129-
url: 'https://splunk.customer.com:8088'
130-
type: splunk
131-
- name: splunk-application-myapp
132-
splunk:
133-
authentication:
134-
token:
135-
key: hecToken
136-
secretName: splunk-application-myapp
137-
sourceType: 'myapp:sourcetype'
138-
url: 'https://splunk.customer.com:8088'
139-
type: splunk
121+
- name: splunk
122+
splunk:
123+
authentication:
124+
token:
125+
key: hecToken
126+
secretName: splunk-secret
127+
payloadKey: .message
128+
sourceType: '{.kubernetes.labels.splunk_sourcetype||"generic_single_line"}'
129+
url: http://splunk.customer.com:8088
130+
type: splunk
140131
pipelines:
141-
- name: splunk-application-general
142-
inputRefs:
143-
- application-general
144-
outputRefs:
145-
- splunk-application-general
146-
- name: splunk-application-myapp
147-
inputRefs:
148-
- application-myapp
149-
outputRefs:
150-
- splunk-application-myapp
151-
```
132+
- inputRefs:
133+
- application
134+
name: forward-pipeline
135+
outputRefs:
136+
- splunk
137+
serviceAccount:
138+
name: logging-admin
139+
----
152140
153141
=== `indexedFields`
154142
@@ -252,17 +240,16 @@ Transformed field:
252240
253241
=== `payloadKey`
254242
255-
By default, `payloadKey` is not set, which means the complete log record is forwarded as the payload.
243+
By default, `payloadKey` is not set, which means the complete log event payload is forwarded. This field can be used to narrow down the final payload to a specific field within the log event. For example, for the payload to contain only the log message, payloadKey should be set to `.message`.
256244
257-
If `sourceType` is not defined, payloadKey can override the default `sourcetype` value of `_json` :
245+
Unless `sourceType` has been defined, the selected `payloadKey` field will be checked and a Splunk source type will be nominated :
258246
259-
* `sourceType`:
247+
* Splunk source type:
260248
** `_json` — used when `payloadKey` points to an object.
261249
** `generic_single_line` — used when the payload is a primitive value (e.g., string, number, boolean).
262250
263251
NOTE: Use `payloadKey` carefully. Selecting a single field as the payload may cause other important information in the log to be dropped, potentially leading to inconsistent or incomplete log events.
264252
265-
266253
=== `host`
267254
268255
The `host` field is *not configurable* through the Cluster Log Forwarder API.

0 commit comments

Comments
 (0)