Skip to content

Commit 3896463

Browse files
committed
LOG-8007: Make AzureMonitor LogType a required, non-empty field
1 parent 4bebcad commit 3896463

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed

api/observability/v1/output_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,11 @@ type AzureMonitor struct {
306306
// Can only contain letters, numbers, and underscores (_), and may not exceed 100 characters.
307307
// https://learn.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api?tabs=powershell#request-headers
308308
//
309+
// +kubebuilder:validation:Required
310+
// +kubebuilder:validation:MinLength:=1
309311
// +kubebuilder:validation:Pattern:="^[a-zA-Z0-9][a-zA-Z0-9_]{0,99}$"
310312
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Log Type",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
311-
LogType string `json:"logType,omitempty"`
313+
LogType string `json:"logType"`
312314

313315
// AzureResourceId the Resource ID of the Azure resource the data should be associated with.
314316
// https://learn.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api?tabs=powershell#request-headers

bundle/manifests/observability.openshift.io_clusterlogforwarders.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ spec:
18331833
LogType the record type of the data that is being submitted.
18341834
Can only contain letters, numbers, and underscores (_), and may not exceed 100 characters.
18351835
https://learn.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api?tabs=powershell#request-headers
1836+
minLength: 1
18361837
pattern: ^[a-zA-Z0-9][a-zA-Z0-9_]{0,99}$
18371838
type: string
18381839
tuning:
@@ -1870,6 +1871,7 @@ spec:
18701871
required:
18711872
- authentication
18721873
- customerId
1874+
- logType
18731875
type: object
18741876
cloudwatch:
18751877
description: Cloudwatch configures forwarding log events to

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ spec:
18331833
LogType the record type of the data that is being submitted.
18341834
Can only contain letters, numbers, and underscores (_), and may not exceed 100 characters.
18351835
https://learn.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api?tabs=powershell#request-headers
1836+
minLength: 1
18361837
pattern: ^[a-zA-Z0-9][a-zA-Z0-9_]{0,99}$
18371838
type: string
18381839
tuning:
@@ -1870,6 +1871,7 @@ spec:
18701871
required:
18711872
- authentication
18721873
- customerId
1874+
- logType
18731875
type: object
18741876
cloudwatch:
18751877
description: Cloudwatch configures forwarding log events to

test/e2e/collection/apivalidations/api_validations_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,13 @@ var _ = Describe("", func() {
112112
Entry("should fail for OTLP with non http URL", "otlp_valid_non_http.yaml", func(out string, err error) {
113113
Expect(err).To(HaveOccurred())
114114
}),
115+
Entry("should fail for AzureMonitor with empty LogType", "azure-monitor-empty-logtype.yaml", func(out string, err error) {
116+
Expect(err).To(HaveOccurred())
117+
Expect(err.Error()).To(MatchRegexp("azureMonitor.logType in body should be at least 1 chars long"))
118+
}),
119+
Entry("should fail for AzureMonitor if no LogType", "azure-monitor-no-logtype.yaml", func(out string, err error) {
120+
Expect(err).To(HaveOccurred())
121+
Expect(err.Error()).To(MatchRegexp("azureMonitor.logType: Required value"))
122+
}),
115123
)
116124
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: my-secret
5+
data:
6+
shared_key: Zm9vLWJhci1rZXk=
7+
---
8+
apiVersion: "observability.openshift.io/v1"
9+
kind: ClusterLogForwarder
10+
metadata:
11+
name: clf-validation-test
12+
spec:
13+
serviceAccount:
14+
name: mine
15+
outputs:
16+
- name: app-logs-azure
17+
type: azureMonitor
18+
azureMonitor:
19+
authentication:
20+
sharedKey:
21+
key: shared_key
22+
secretName: my-secret
23+
customerId: 1111-111-1111-1111-11111
24+
logType: ""
25+
pipelines:
26+
- name: my-logs
27+
inputRefs:
28+
- application
29+
outputRefs:
30+
- app-logs-azure
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: my-secret
5+
data:
6+
shared_key: Zm9vLWJhci1rZXk=
7+
---
8+
apiVersion: "observability.openshift.io/v1"
9+
kind: ClusterLogForwarder
10+
metadata:
11+
name: clf-validation-test
12+
spec:
13+
serviceAccount:
14+
name: mine
15+
outputs:
16+
- name: app-logs-azure
17+
type: azureMonitor
18+
azureMonitor:
19+
authentication:
20+
sharedKey:
21+
key: shared_key
22+
secretName: my-secret
23+
customerId: 1111-111-1111-1111-11111
24+
pipelines:
25+
- name: my-logs
26+
inputRefs:
27+
- application
28+
outputRefs:
29+
- app-logs-azure

0 commit comments

Comments
 (0)