Skip to content

Commit

Permalink
Merge pull request #1779 from justinsb/logmetric_resourceid
Browse files Browse the repository at this point in the history
LoggingLogMetric: honor resourceID on creation
  • Loading branch information
google-oss-prow[bot] authored May 13, 2024
2 parents fcf0cbf + c93aa63 commit 9171d9b
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 792 deletions.
3 changes: 2 additions & 1 deletion pkg/controller/direct/logging/logmetric_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions pkg/controller/direct/logging/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -61,7 +59,7 @@ spec:
valueType: DISTRIBUTION
projectRef:
external: projects/${projectId}
resourceID: logginglogmetric-${uniqueId}
resourceID: linearlogmetric-${uniqueId}
valueExtractor: EXTRACT(jsonPayload.response)
status:
conditions:
Expand All @@ -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"
Loading

0 comments on commit 9171d9b

Please sign in to comment.