From c93aa63a298def15159f6db1bb1e551e61166b2a Mon Sep 17 00:00:00 2001 From: justinsb Date: Mon, 13 May 2024 09:46:10 -0400 Subject: [PATCH] LoggingLogMetric: honor resourceID on creation By passing the spec to KRMToAPI, we can defend against this. --- .../direct/logging/logmetric_controller.go | 3 +- pkg/controller/direct/logging/utils.go | 9 +- ...nerated_object_linearlogmetric.golden.yaml | 12 +- .../linearlogmetric/_http.log | 839 ++---------------- .../linearlogmetric/create.yaml | 1 + .../linearlogmetric/update.yaml | 1 + 6 files changed, 73 insertions(+), 792 deletions(-) diff --git a/pkg/controller/direct/logging/logmetric_controller.go b/pkg/controller/direct/logging/logmetric_controller.go index fc1729fe77..ccf91908e1 100644 --- a/pkg/controller/direct/logging/logmetric_controller.go +++ b/pkg/controller/direct/logging/logmetric_controller.go @@ -173,7 +173,8 @@ func (a *logMetricAdapter) Create(ctx context.Context, u *unstructured.Unstructu } } - logMetric := convertKCCtoAPI(a.desired) + logMetric := convertKCCtoAPI(&a.desired.Spec) + logMetric.Name = a.resourceID createRequest := a.logMetricClient.Create("projects/"+projectID, logMetric) log.V(2).Info("creating logMetric", "request", &createRequest, "name", logMetric.Name) diff --git a/pkg/controller/direct/logging/utils.go b/pkg/controller/direct/logging/utils.go index dba9b31f9a..ef964bb6c5 100644 --- a/pkg/controller/direct/logging/utils.go +++ b/pkg/controller/direct/logging/utils.go @@ -241,14 +241,11 @@ func convertKCCtoAPIForBucketOptions(kccObj *krm.LogmetricBucketOptions) *api.Bu return apiObj } -func convertKCCtoAPI(kccObj *krm.LoggingLogMetric) *api.LogMetric { - if kccObj == nil { +func convertKCCtoAPI(kccObjSpec *krm.LoggingLogMetricSpec) *api.LogMetric { + if kccObjSpec == nil { return nil } - kccObjSpec := kccObj.Spec - logMetric := &api.LogMetric{ - Name: kccObj.GetName(), - } + logMetric := &api.LogMetric{} if kccObjSpec.BucketOptions != nil { logMetric.BucketOptions = convertKCCtoAPIForBucketOptions(kccObjSpec.BucketOptions) diff --git a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/_generated_object_linearlogmetric.golden.yaml b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/_generated_object_linearlogmetric.golden.yaml index 7c48877c55..67720ec932 100644 --- a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/_generated_object_linearlogmetric.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/_generated_object_linearlogmetric.golden.yaml @@ -17,12 +17,10 @@ kind: LoggingLogMetric metadata: annotations: cnrm.cloud.google.com/management-conflict-prevention-policy: none - cnrm.cloud.google.com/mutable-but-unreadable-fields: '{"spec":{"metricDescriptor":{"launchStage":"PRELAUNCH","metadata":{"ingestDelay":"3.5s","samplePeriod":"3.5s"}}}}' - cnrm.cloud.google.com/state-into-spec: merge finalizers: - cnrm.cloud.google.com/finalizer - cnrm.cloud.google.com/deletion-defender - generation: 3 + generation: 2 labels: cnrm-test: "true" name: logginglogmetric-${uniqueId} @@ -61,7 +59,7 @@ spec: valueType: DISTRIBUTION projectRef: external: projects/${projectId} - resourceID: logginglogmetric-${uniqueId} + resourceID: linearlogmetric-${uniqueId} valueExtractor: EXTRACT(jsonPayload.response) status: conditions: @@ -73,7 +71,7 @@ status: createTime: "1970-01-01T00:00:00Z" metricDescriptor: description: An updated sample log metric - name: projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId} - type: logging.googleapis.com/user/logginglogmetric-${uniqueId} - observedGeneration: 3 + name: projects/${projectId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId} + type: logging.googleapis.com/user/linearlogmetric-${uniqueId} + observedGeneration: 2 updateTime: "1970-01-01T00:00:00Z" diff --git a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/_http.log b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/_http.log index 199b57b689..e9518ebc69 100644 --- a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/_http.log @@ -1,524 +1,8 @@ -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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 logginglogmetric-${uniqueId} does not exist.", - "status": "NOT_FOUND" - } -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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 logginglogmetric-${uniqueId} does not exist.", - "status": "NOT_FOUND" - } -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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 logginglogmetric-${uniqueId} does not exist.", - "status": "NOT_FOUND" - } -} - ---- - -POST https://logging.googleapis.com/v2/projects/${projectId}/metrics?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -{ - "bucketOptions": { - "linearBuckets": { - "numFiniteBuckets": 3, - "offset": 1.5, - "width": 3.5 - } - }, - "description": "A sample log metric", - "disabled": false, - "filter": "resource.type=gae_app AND severity\u003c=ERROR", - "labelExtractors": { - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "displayName": "sample-descriptor", - "labels": [ - { - "description": "amount of matter", - "key": "mass", - "valueType": "STRING" - }, - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - } - ], - "launchStage": "UNIMPLEMENTED", - "metadata": { - "ingestDelay": "2s", - "samplePeriod": "5s" - }, - "metricKind": "DELTA", - "unit": "bit", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "valueExtractor": "EXTRACT(jsonPayload.request)" -} - -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": { - "linearBuckets": { - "numFiniteBuckets": 3, - "offset": 1.5, - "width": 3.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "A sample log metric", - "filter": "resource.type=gae_app AND severity\u003c=ERROR", - "labelExtractors": { - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "A sample log metric", - "displayName": "sample-descriptor", - "labels": [ - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "bit", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", - "valueExtractor": "EXTRACT(jsonPayload.request)" -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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": { - "linearBuckets": { - "numFiniteBuckets": 3, - "offset": 1.5, - "width": 3.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "A sample log metric", - "filter": "resource.type=gae_app AND severity\u003c=ERROR", - "labelExtractors": { - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "A sample log metric", - "displayName": "sample-descriptor", - "labels": [ - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "bit", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", - "valueExtractor": "EXTRACT(jsonPayload.request)" -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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": { - "linearBuckets": { - "numFiniteBuckets": 3, - "offset": 1.5, - "width": 3.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "A sample log metric", - "filter": "resource.type=gae_app AND severity\u003c=ERROR", - "labelExtractors": { - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "A sample log metric", - "displayName": "sample-descriptor", - "labels": [ - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "bit", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", - "valueExtractor": "EXTRACT(jsonPayload.request)" -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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": { - "linearBuckets": { - "numFiniteBuckets": 3, - "offset": 1.5, - "width": 3.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "A sample log metric", - "filter": "resource.type=gae_app AND severity\u003c=ERROR", - "labelExtractors": { - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "A sample log metric", - "displayName": "sample-descriptor", - "labels": [ - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "bit", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", - "valueExtractor": "EXTRACT(jsonPayload.request)" -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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": { - "linearBuckets": { - "numFiniteBuckets": 3, - "offset": 1.5, - "width": 3.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "A sample log metric", - "filter": "resource.type=gae_app AND severity\u003c=ERROR", - "labelExtractors": { - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "A sample log metric", - "displayName": "sample-descriptor", - "labels": [ - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "bit", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", - "valueExtractor": "EXTRACT(jsonPayload.request)" -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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": { - "linearBuckets": { - "numFiniteBuckets": 3, - "offset": 1.5, - "width": 3.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "A sample log metric", - "filter": "resource.type=gae_app AND severity\u003c=ERROR", - "labelExtractors": { - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "A sample log metric", - "displayName": "sample-descriptor", - "labels": [ - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "bit", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", - "valueExtractor": "EXTRACT(jsonPayload.request)" -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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": { - "linearBuckets": { - "numFiniteBuckets": 3, - "offset": 1.5, - "width": 3.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "A sample log metric", - "filter": "resource.type=gae_app AND severity\u003c=ERROR", - "labelExtractors": { - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "A sample log metric", - "displayName": "sample-descriptor", - "labels": [ - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "bit", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", - "valueExtractor": "EXTRACT(jsonPayload.request)" -} - ---- +GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/linearlogmetric-${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 -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -200 OK +404 Not Found Cache-Control: private Content-Type: application/json; charset=UTF-8 Server: ESF @@ -529,6 +13,21 @@ X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 +{ + "error": { + "code": 404, + "message": "Metric linearlogmetric-${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": { "linearBuckets": { @@ -537,7 +36,6 @@ X-Xss-Protection: 0 "width": 3.5 } }, - "createTime": "2024-04-01T12:34:56.123456Z", "description": "A sample log metric", "filter": "resource.type=gae_app AND severity\u003c=ERROR", "labelExtractors": { @@ -545,36 +43,33 @@ X-Xss-Protection: 0 "sku": "EXTRACT(jsonPayload.id)" }, "metricDescriptor": { - "description": "A sample log metric", "displayName": "sample-descriptor", "labels": [ + { + "description": "amount of matter", + "key": "mass", + "valueType": "STRING" + }, { "description": "identifying number for item", "key": "sku", "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" } ], + "launchStage": "UNIMPLEMENTED", + "metadata": { + "ingestDelay": "2s", + "samplePeriod": "5s" + }, "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", + "name": "sample-descriptor", "unit": "bit", "valueType": "DISTRIBUTION" }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", + "name": "linearlogmetric-${uniqueId}", "valueExtractor": "EXTRACT(jsonPayload.request)" } ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - 200 OK Cache-Control: private Content-Type: application/json; charset=UTF-8 @@ -605,32 +100,32 @@ X-Xss-Protection: 0 "description": "A sample log metric", "displayName": "sample-descriptor", "labels": [ + { + "description": "amount of matter", + "key": "mass" + }, { "description": "identifying number for item", "key": "sku", "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" } ], "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}", + "type": "logging.googleapis.com/user/linearlogmetric-${uniqueId}", "unit": "bit", "valueType": "DISTRIBUTION" }, - "name": "logginglogmetric-${uniqueId}", + "name": "linearlogmetric-${uniqueId}", "updateTime": "2024-04-01T12:34:56.123456Z", "valueExtractor": "EXTRACT(jsonPayload.request)" } --- -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 +GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/linearlogmetric-${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 @@ -662,32 +157,33 @@ X-Xss-Protection: 0 "description": "A sample log metric", "displayName": "sample-descriptor", "labels": [ + { + "description": "amount of matter", + "key": "mass" + }, { "description": "identifying number for item", "key": "sku", "valueType": "INT64" - }, - { - "description": "amount of matter", - "key": "mass" } ], "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}", + "type": "logging.googleapis.com/user/linearlogmetric-${uniqueId}", "unit": "bit", "valueType": "DISTRIBUTION" }, - "name": "logginglogmetric-${uniqueId}", + "name": "linearlogmetric-${uniqueId}", "updateTime": "2024-04-01T12:34:56.123456Z", "valueExtractor": "EXTRACT(jsonPayload.request)" } --- -PUT https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json +PUT https://logging.googleapis.com/v2/projects/${projectId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 +User-Agent: google-api-go-client/0.5 +X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0 { "bucketOptions": { @@ -697,6 +193,7 @@ User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 "width": 2.5 } }, + "createTime": "2024-04-01T12:34:56.123456Z", "description": "An updated sample log metric", "disabled": true, "filter": "resource.type=gae_app AND severity\u003e=ERROR", @@ -730,140 +227,15 @@ User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 "samplePeriod": "3.5s" }, "metricKind": "DELTA", + "name": "updated-sample-descriptor", "unit": "s", "valueType": "DISTRIBUTION" }, - "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": { - "linearBuckets": { - "numFiniteBuckets": 4, - "offset": 0.5, - "width": 2.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "An updated sample log metric", - "disabled": true, - "filter": "resource.type=gae_app AND severity\u003e=ERROR", - "labelExtractors": { - "hasMass": "REGEXP_EXTRACT(jsonPayload.request, \".*([1-9]).*\")", - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "An updated sample log metric", - "displayName": "updated-sample-descriptor", - "labels": [ - { - "description": "amount of matter", - "key": "mass" - }, - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, - { - "description": "whether the item has a mass", - "key": "hasMass", - "valueType": "BOOL" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "s", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", - "valueExtractor": "EXTRACT(jsonPayload.response)" -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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": { - "linearBuckets": { - "numFiniteBuckets": 4, - "offset": 0.5, - "width": 2.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "An updated sample log metric", - "disabled": true, - "filter": "resource.type=gae_app AND severity\u003e=ERROR", - "labelExtractors": { - "hasMass": "REGEXP_EXTRACT(jsonPayload.request, \".*([1-9]).*\")", - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "An updated sample log metric", - "displayName": "updated-sample-descriptor", - "labels": [ - { - "description": "amount of matter", - "key": "mass" - }, - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, - { - "description": "whether the item has a mass", - "key": "hasMass", - "valueType": "BOOL" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "s", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", + "name": "linearlogmetric-${uniqueId}", "updateTime": "2024-04-01T12:34:56.123456Z", "valueExtractor": "EXTRACT(jsonPayload.response)" } ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - 200 OK Cache-Control: private Content-Type: application/json; charset=UTF-8 @@ -900,97 +272,33 @@ X-Xss-Protection: 0 "description": "amount of matter", "key": "mass" }, - { - "description": "identifying number for item", - "key": "sku", - "valueType": "INT64" - }, { "description": "whether the item has a mass", "key": "hasMass", "valueType": "BOOL" - } - ], - "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "unit": "s", - "valueType": "DISTRIBUTION" - }, - "name": "logginglogmetric-${uniqueId}", - "updateTime": "2024-04-01T12:34:56.123456Z", - "valueExtractor": "EXTRACT(jsonPayload.response)" -} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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": { - "linearBuckets": { - "numFiniteBuckets": 4, - "offset": 0.5, - "width": 2.5 - } - }, - "createTime": "2024-04-01T12:34:56.123456Z", - "description": "An updated sample log metric", - "disabled": true, - "filter": "resource.type=gae_app AND severity\u003e=ERROR", - "labelExtractors": { - "hasMass": "REGEXP_EXTRACT(jsonPayload.request, \".*([1-9]).*\")", - "mass": "EXTRACT(jsonPayload.request)", - "sku": "EXTRACT(jsonPayload.id)" - }, - "metricDescriptor": { - "description": "An updated sample log metric", - "displayName": "updated-sample-descriptor", - "labels": [ - { - "description": "amount of matter", - "key": "mass" }, { "description": "identifying number for item", "key": "sku", "valueType": "INT64" - }, - { - "description": "whether the item has a mass", - "key": "hasMass", - "valueType": "BOOL" } ], "metricKind": "DELTA", - "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}", - "type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}", + "name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}", + "type": "logging.googleapis.com/user/linearlogmetric-${uniqueId}", "unit": "s", "valueType": "DISTRIBUTION" }, - "name": "logginglogmetric-${uniqueId}", + "name": "linearlogmetric-${uniqueId}", "updateTime": "2024-04-01T12:34:56.123456Z", "valueExtractor": "EXTRACT(jsonPayload.response)" } --- -DELETE https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 +DELETE https://logging.googleapis.com/v2/projects/${projectId}/metrics/linearlogmetric-${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 @@ -1003,29 +311,4 @@ X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 -{} - ---- - -GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json -Content-Type: application/json -User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 - -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 logginglogmetric-${uniqueId} does not exist", - "status": "NOT_FOUND" - } -} \ No newline at end of file +{} \ No newline at end of file diff --git a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/create.yaml b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/create.yaml index 8558234eb6..aa459966ff 100644 --- a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/create.yaml +++ b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/create.yaml @@ -47,3 +47,4 @@ spec: offset: 1.5 projectRef: external: "projects/${projectId}" + resourceID: linearlogmetric-${uniqueId} \ No newline at end of file diff --git a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/update.yaml b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/update.yaml index ddd3acd9aa..5720b5b365 100644 --- a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/update.yaml +++ b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/linearlogmetric/update.yaml @@ -51,3 +51,4 @@ spec: offset: 0.5 projectRef: external: "projects/${projectId}" + resourceID: linearlogmetric-${uniqueId}