Skip to content

Commit 875d760

Browse files
authored
Implement round-trip KRM fuzzer for MonitoringMonitoredProject (#11317)
This Pull Request implements a type-safe round-trip KRM fuzzer for `MonitoringMonitoredProject` under `pkg/controller/direct/monitoring/monitoredproject_fuzzer.go` using the `fuzztesting` framework. Specifically: - Refactored and renamed the pre-existing fuzzer file from `monitoringmonitoredproject_fuzzer.go` to `monitoredproject_fuzzer.go`. - Upgraded the fuzzer to use the type-safe, generic `NewKRMTypedFuzzer` API. - Added explicit field comparison comments detailing how KRM Spec and Status fields map to the underlying GCP proto. - Added the corresponding fuzzer journal entry under `.gemini/skills/create-fuzzer/journal/monitoringmonitoredproject.md`. Fixes #11316
2 parents 88b052a + 4c6c9bb commit 875d760

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
When implementing the round-trip KRM fuzzer for MonitoringMonitoredProject, we observed:
2+
1. `MonitoringMonitoredProject` maps its Spec fields (`metricsScope` and `resourceID`) to the single GCP proto field `.name` under the pattern `locations/global/metricsScopes/{metrics_scope}/projects/{project}` in custom, handcoded mapper functions:
3+
- `MonitoringMonitoredProjectSpec_FromProto` / `MonitoringMonitoredProjectSpec_ToProto`
4+
- `MonitoringMonitoredProjectStatus_FromProto` / `MonitoringMonitoredProjectStatus_ToProto`
5+
2. We implemented a complete, type-safe generic round-trip KRM fuzzer at `pkg/controller/direct/monitoring/monitoredproject_fuzzer.go` using `fuzztesting.RegisterKRMFuzzer`.
6+
3. The GCP proto status field `.create_time` maps to KRM status `createTime` and was correctly registered as `f.StatusField(".create_time")`.
7+
4. The GCP proto identity field `.name` was correctly registered as `f.Unimplemented_Identity(".name")`, allowing both Spec and Status round-trip fuzz tests to pass flawlessly.

pkg/controller/direct/monitoring/monitoringmonitoredproject_fuzzer.go renamed to pkg/controller/direct/monitoring/monitoredproject_fuzzer.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
// +tool:fuzz-gen
1616
// proto.message: google.monitoring.metricsscope.v1.MonitoredProject
17-
// api.group: monitoring.cnrm.cloud.google.com
17+
// krm.group: monitoring.cnrm.cloud.google.com
18+
// krm.kind: MonitoringMonitoredProject
1819

1920
package monitoring
2021

2122
import (
2223
metricsscopepb "cloud.google.com/go/monitoring/metricsscope/apiv1/metricsscopepb"
24+
krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/monitoring/v1beta1"
2325
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/fuzztesting"
2426
)
2527

@@ -28,15 +30,24 @@ func init() {
2830
}
2931

3032
func monitoringMonitoredProjectFuzzer() fuzztesting.KRMFuzzer {
31-
f := fuzztesting.NewKRMTypedFuzzer(&metricsscopepb.MonitoredProject{},
32-
MonitoringMonitoredProjectSpec_FromProto, MonitoringMonitoredProjectSpec_ToProto,
33-
MonitoringMonitoredProjectStatus_FromProto, MonitoringMonitoredProjectStatus_ToProto,
33+
f := fuzztesting.NewKRMTypedFuzzer[*metricsscopepb.MonitoredProject, krm.MonitoringMonitoredProjectSpec, krm.MonitoringMonitoredProjectStatus](
34+
&metricsscopepb.MonitoredProject{},
35+
MonitoringMonitoredProjectSpec_FromProto,
36+
MonitoringMonitoredProjectSpec_ToProto,
37+
MonitoringMonitoredProjectStatus_FromProto,
38+
MonitoringMonitoredProjectStatus_ToProto,
3439
)
3540

41+
// Field comparison between KRM Spec (MonitoringMonitoredProjectSpec) and GCP Proto (google.monitoring.metricsscope.v1.MonitoredProject):
42+
// - MetricsScope (KRM Spec) and ResourceID (KRM Spec) are combined into `.name` in Proto representing
43+
// "locations/global/metricsScopes/{metrics_scope}/projects/{project}".
44+
// - CreateTime (KRM Status) maps to `.create_time` (GCP Proto).
45+
3646
// Status fields
3747
f.StatusField(".create_time")
3848

39-
// Identity/unimplemented fields
49+
// Identity and Unimplemented fields
50+
// - Name (GCP Proto) contains both the parent metrics scope and the project ID.
4051
f.Unimplemented_Identity(".name")
4152

4253
return f

0 commit comments

Comments
 (0)