From 7e7db4970b558047663b0994af1256ea68ad7830 Mon Sep 17 00:00:00 2001 From: justinsb Date: Mon, 13 May 2024 10:17:48 -0400 Subject: [PATCH] tests: add test for LoggingLogMetric lazy reconciliation A little hacky right now, we don't have a better mechanism than sleeping and trying to coordinate timings. --- tests/e2e/script_test.go | 5 + .../direct/llm_lazy_reconcile/_http00.log | 179 ++++++++++++++++ .../direct/llm_lazy_reconcile/_http01.log | 195 ++++++++++++++++++ .../direct/llm_lazy_reconcile/_object00.yaml | 55 +++++ .../direct/llm_lazy_reconcile/_object01.yaml | 55 +++++ .../direct/llm_lazy_reconcile/script.yaml | 40 ++++ 6 files changed, 529 insertions(+) create mode 100644 tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_http00.log create mode 100644 tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_http01.log create mode 100644 tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_object00.yaml create mode 100644 tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_object01.yaml create mode 100644 tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/script.yaml diff --git a/tests/e2e/script_test.go b/tests/e2e/script_test.go index d87372c41f..bfed166243 100644 --- a/tests/e2e/script_test.go +++ b/tests/e2e/script_test.go @@ -130,6 +130,11 @@ func TestE2EScript(t *testing.T) { exportResource = nil shouldGetKubeObject = false + case "SLEEP": + // Allow some time for reconcile + // Maybe we should instead wait for observedState + time.Sleep(2 * time.Second) + case "DELETE-NO-WAIT": create.DeleteResources(h, create.CreateDeleteTestOptions{Create: []*unstructured.Unstructured{obj}, SkipWaitForDelete: true}) diff --git a/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_http00.log b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_http00.log new file mode 100644 index 0000000000..1f03d0519c --- /dev/null +++ b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_http00.log @@ -0,0 +1,179 @@ +GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/lazyreconcile-${uniqueId}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 +X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0 + +404 Not Found +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "error": { + "code": 404, + "message": "Metric lazyreconcile-${uniqueId} does not exist.", + "status": "NOT_FOUND" + } +} + +--- + +POST https://logging.googleapis.com/v2/projects/${projectId}/metrics?alt=json&prettyPrint=false +Content-Type: application/json +User-Agent: google-api-go-client/0.5 +X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "type": "logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} + +--- + +GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/lazyreconcile-${uniqueId}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 +X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0 + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "type": "logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} + +--- + +PUT https://logging.googleapis.com/v2/projects/${projectId}/metrics/lazyreconcile-${uniqueId}?alt=json&prettyPrint=false +Content-Type: application/json +User-Agent: google-api-go-client/0.5 +X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "type": "logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} \ No newline at end of file diff --git a/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_http01.log b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_http01.log new file mode 100644 index 0000000000..28c5157665 --- /dev/null +++ b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_http01.log @@ -0,0 +1,195 @@ +GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/lazyreconcile-${uniqueId}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 +X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0 + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "type": "logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} + +--- + +PUT https://logging.googleapis.com/v2/projects/${projectId}/metrics/lazyreconcile-${uniqueId}?alt=json&prettyPrint=false +Content-Type: application/json +User-Agent: google-api-go-client/0.5 +X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "type": "logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} + +--- + +GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/lazyreconcile-${uniqueId}?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 +X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0 + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "type": "logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} + +--- + +PUT https://logging.googleapis.com/v2/projects/${projectId}/metrics/lazyreconcile-${uniqueId}?alt=json&prettyPrint=false +Content-Type: application/json +User-Agent: google-api-go-client/0.5 +X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 2.5, + 5 + ] + } + }, + "createTime": "2024-04-01T12:34:56.123456Z", + "filter": "resource.type=gae_app AND severity\u003e=ERROR", + "metricDescriptor": { + "metricKind": "DELTA", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "type": "logging.googleapis.com/user/lazyreconcile-${uniqueId}", + "valueType": "DISTRIBUTION" + }, + "name": "lazyreconcile-${uniqueId}", + "updateTime": "2024-04-01T12:34:56.123456Z", + "valueExtractor": "EXTRACT(jsonPayload.response)" +} \ No newline at end of file diff --git a/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_object00.yaml b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_object00.yaml new file mode 100644 index 0000000000..d8b902c579 --- /dev/null +++ b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_object00.yaml @@ -0,0 +1,55 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: logging.cnrm.cloud.google.com/v1beta1 +kind: LoggingLogMetric +metadata: + annotations: + cnrm.cloud.google.com/management-conflict-prevention-policy: none + cnrm.cloud.google.com/project-id: ${projectId} + cnrm.cloud.google.com/reconcile-interval-in-seconds: "1" + cnrm.cloud.google.com/state-into-spec: absent + finalizers: + - cnrm.cloud.google.com/finalizer + - cnrm.cloud.google.com/deletion-defender + generation: 2 + name: lazyreconcile-${uniqueId} + namespace: ${projectId} +spec: + bucketOptions: + explicitBuckets: + bounds: + - 2.5 + - 5 + filter: resource.type=gae_app AND severity>=ERROR + metricDescriptor: + metricKind: DELTA + valueType: DISTRIBUTION + projectRef: + external: projects/${projectId} + resourceID: lazyreconcile-${uniqueId} + valueExtractor: EXTRACT(jsonPayload.response) +status: + conditions: + - lastTransitionTime: "1970-01-01T00:00:00Z" + message: The resource is up to date + reason: UpToDate + status: "True" + type: Ready + createTime: "1970-01-01T00:00:00Z" + metricDescriptor: + name: projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId} + type: logging.googleapis.com/user/lazyreconcile-${uniqueId} + observedGeneration: 2 + updateTime: "1970-01-01T00:00:00Z" diff --git a/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_object01.yaml b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_object01.yaml new file mode 100644 index 0000000000..d8b902c579 --- /dev/null +++ b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_object01.yaml @@ -0,0 +1,55 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: logging.cnrm.cloud.google.com/v1beta1 +kind: LoggingLogMetric +metadata: + annotations: + cnrm.cloud.google.com/management-conflict-prevention-policy: none + cnrm.cloud.google.com/project-id: ${projectId} + cnrm.cloud.google.com/reconcile-interval-in-seconds: "1" + cnrm.cloud.google.com/state-into-spec: absent + finalizers: + - cnrm.cloud.google.com/finalizer + - cnrm.cloud.google.com/deletion-defender + generation: 2 + name: lazyreconcile-${uniqueId} + namespace: ${projectId} +spec: + bucketOptions: + explicitBuckets: + bounds: + - 2.5 + - 5 + filter: resource.type=gae_app AND severity>=ERROR + metricDescriptor: + metricKind: DELTA + valueType: DISTRIBUTION + projectRef: + external: projects/${projectId} + resourceID: lazyreconcile-${uniqueId} + valueExtractor: EXTRACT(jsonPayload.response) +status: + conditions: + - lastTransitionTime: "1970-01-01T00:00:00Z" + message: The resource is up to date + reason: UpToDate + status: "True" + type: Ready + createTime: "1970-01-01T00:00:00Z" + metricDescriptor: + name: projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId} + type: logging.googleapis.com/user/lazyreconcile-${uniqueId} + observedGeneration: 2 + updateTime: "1970-01-01T00:00:00Z" diff --git a/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/script.yaml b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/script.yaml new file mode 100644 index 0000000000..486862908e --- /dev/null +++ b/tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/script.yaml @@ -0,0 +1,40 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: logging.cnrm.cloud.google.com/v1beta1 +kind: LoggingLogMetric +metadata: + name: lazyreconcile-${uniqueId} + annotations: + cnrm.cloud.google.com/state-into-spec: absent + cnrm.cloud.google.com/reconcile-interval-in-seconds : "1" +spec: + filter: "resource.type=gae_app AND severity>=ERROR" + metricDescriptor: + metricKind: "DELTA" + valueType: "DISTRIBUTION" + valueExtractor: "EXTRACT(jsonPayload.response)" + bucketOptions: + explicitBuckets: + bounds: + - 2.5 + - 5 + projectRef: + external: "projects/${projectId}" +--- +TEST: SLEEP +apiVersion: logging.cnrm.cloud.google.com/v1beta1 +kind: LoggingLogMetric +metadata: + name: lazyreconcile-${uniqueId}