Skip to content

Commit f79124e

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 d6f232d commit f79124e

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
@@ -1262,6 +1262,7 @@ type SplunkAuthentication struct {
12621262

12631263
// Splunk Deliver log data to Splunk’s HTTP Event Collector
12641264
// Provides optional extra properties for `type: splunk_hec` ('splunk_hec_logs' after Vector 0.23
1265+
// +kubebuilder:validation:XValidation:rule="!has(self.sourceType) || has(self.payloadKey)",message="sourceType can only be set when payloadKey is defined"
12651266
type Splunk struct {
12661267
// Authentication sets credentials for authenticating the requests.
12671268
//
@@ -1331,19 +1332,30 @@ type Splunk struct {
13311332
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Source",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
13321333
Source string `json:"source,omitempty"`
13331334

1334-
// SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
1335-
// 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.
1335+
// SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
1336+
//
1337+
// 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.
1338+
//
1339+
// 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.
13361340
// Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
13371341
//
1342+
// 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.
1343+
// A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
1344+
//
1345+
// Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
1346+
//
13381347
// Examples:
13391348
//
1340-
// 1. "access_combined"
1349+
// 1. "log4j"
13411350
//
1342-
// 2. "log4j"
1351+
// 2. foo-{.bar||"none"}
13431352
//
1344-
// 3. "my:custom:sourcetype"
1353+
// 3. {.foo||.bar||"missing"}
1354+
//
1355+
// 4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
13451356
//
13461357
// +kubebuilder:validation:Optional
1358+
// +kubebuilder:validation:Pattern:=`^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$`
13471359
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="SourceType",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
13481360
SourceType string `json:"sourceType,omitempty"`
13491361

bundle/manifests/cluster-logging.clusterserviceversion.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,17 +1943,27 @@ spec:
19431943
x-descriptors:
19441944
- urn:alm:descriptor:com.tectonic.ui:text
19451945
- description: |-
1946-
SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
1947-
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.
1946+
SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
1947+
1948+
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.
1949+
1950+
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.
19481951
Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
19491952
1953+
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.
1954+
A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
1955+
1956+
Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
1957+
19501958
Examples:
19511959
1952-
1. "access_combined"
1960+
1. "log4j"
1961+
1962+
2. foo-{.bar||"none"}
19531963
1954-
2. "log4j"
1964+
3. {.foo||.bar||"missing"}
19551965
1956-
3. "my:custom:sourcetype"
1966+
4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
19571967
displayName: SourceType
19581968
path: outputs[0].splunk.sourceType
19591969
x-descriptors:

bundle/manifests/observability.openshift.io_clusterlogforwarders.yaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3893,17 +3893,28 @@ spec:
38933893
type: string
38943894
sourceType:
38953895
description: |-
3896-
SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
3897-
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.
3896+
SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
3897+
3898+
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.
3899+
3900+
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.
38983901
Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
38993902
3903+
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.
3904+
A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
3905+
3906+
Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
3907+
39003908
Examples:
39013909
3902-
1. "access_combined"
3910+
1. "log4j"
3911+
3912+
2. foo-{.bar||"none"}
39033913
3904-
2. "log4j"
3914+
3. {.foo||.bar||"missing"}
39053915
3906-
3. "my:custom:sourcetype"
3916+
4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
3917+
pattern: ^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$
39073918
type: string
39083919
tuning:
39093920
description: Tuning specs tuning for the output
@@ -3958,6 +3969,9 @@ spec:
39583969
- authentication
39593970
- url
39603971
type: object
3972+
x-kubernetes-validations:
3973+
- message: sourceType can only be set when payloadKey is defined
3974+
rule: '!has(self.sourceType) || has(self.payloadKey)'
39613975
syslog:
39623976
description: Syslog configures forwarding log events to a receiver
39633977
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
@@ -3893,17 +3893,28 @@ spec:
38933893
type: string
38943894
sourceType:
38953895
description: |-
3896-
SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
3897-
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.
3896+
SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
3897+
3898+
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.
3899+
3900+
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.
38983901
Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
38993902
3903+
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.
3904+
A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
3905+
3906+
Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
3907+
39003908
Examples:
39013909
3902-
1. "access_combined"
3910+
1. "log4j"
3911+
3912+
2. foo-{.bar||"none"}
39033913
3904-
2. "log4j"
3914+
3. {.foo||.bar||"missing"}
39053915
3906-
3. "my:custom:sourcetype"
3916+
4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
3917+
pattern: ^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$
39073918
type: string
39083919
tuning:
39093920
description: Tuning specs tuning for the output
@@ -3958,6 +3969,9 @@ spec:
39583969
- authentication
39593970
- url
39603971
type: object
3972+
x-kubernetes-validations:
3973+
- message: sourceType can only be set when payloadKey is defined
3974+
rule: '!has(self.sourceType) || has(self.payloadKey)'
39613975
syslog:
39623976
description: Syslog configures forwarding log events to a receiver
39633977
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
@@ -1866,17 +1866,27 @@ spec:
18661866
x-descriptors:
18671867
- urn:alm:descriptor:com.tectonic.ui:text
18681868
- description: |-
1869-
SourceType can be used to specify a pretrained or custom sourcetype in Splunk.
1870-
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.
1869+
SourceType can be used to specify a pretrained or custom source type in Splunk, but can only be set when PayloadKey is defined.
1870+
1871+
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.
1872+
1873+
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.
18711874
Details in: docs/features/logforwarding/outputs/splunk-forwarding.adoc
18721875
1876+
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.
1877+
A dynamic value is encased in single curly brackets `{}` and MUST end with a static fallback value separated with `||`.
1878+
1879+
Static values can only contain alphanumeric characters along with dashes, underscores, dots and forward slashes.
1880+
18731881
Examples:
18741882
1875-
1. "access_combined"
1883+
1. "log4j"
1884+
1885+
2. foo-{.bar||"none"}
18761886
1877-
2. "log4j"
1887+
3. {.foo||.bar||"missing"}
18781888
1879-
3. "my:custom:sourcetype"
1889+
4. foo.{.bar.baz||.qux.quux.corge||.grault||"nil"}-waldo.fred{.plugh||"none"}
18801890
displayName: SourceType
18811891
path: outputs[0].splunk.sourceType
18821892
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)