Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: create generated mappers and roundtrip test for Dashboard #1862

Conversation

justinsb
Copy link
Collaborator

@justinsb justinsb commented May 21, 2024

This allows us to see unsupported fields.

Copy link
Collaborator

@acpana acpana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions but overall looks really cool, especially the fuzzer

Descriptor() protoreflect.EnumDescriptor
}

func Enum_ToProto[U ProtoEnum](ctx *MapContext, in *string) U {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

big nit: Going to leave it up to you but could we rename ctx to mapCtx or something that doesn't make me think of the context.Context one 😛

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A much better name, thank you!


inValue := ValueOf(in)
if inValue == "" {
unspecifiedValue := U(int32(0)) // defaultU.New(protoreflect.EnumNumber(0)).(U)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my own learning, here and everywhere else, why not int64?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, good question. It shouldn't matter in go, because constant values are untyped (or something). Removed the int32 entirely, and it seems to still work :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(proto.EnumNumber is int32, so it is actually int32 at the proto level, though proto int64 vs int32 is largely academic anyway as they both use variable length encoding, I believe)

Comment on lines 87 to 91
// if in == nil {
// return nil
// }

// v := *in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if in == nil {
// return nil
// }
// v := *in

remove?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done!

if count > 4 {
return
}
seconds := rand.Intn(365 * 24 * 60 * 60)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to seed rand for determinism ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will rename to randStream. And we do, the first "real" line of FuzzFromProto

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 💯 ; I'm wondering 1) if we want this to be in the direct package or test package long term and 2) if we can iterate over al the resources we care about with the same core.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I am just starting it here, but I think we want to move it out pretty fast into a shared library!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait how do we generate this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using #1613 ... the gotcha is that I don't think we are all agreed on whether we should generate it this way. I hope to achieve that consensus when we all meet and reconcile our approaches.

If you want to use the tool, feel free though! I think we're coming up with a way of doing it in this stream of PRs:

  1. Get mockgcp running to understand the API and make testing easier
  2. Add a few more tests and capture some golden output
  3. Add to the direct test script
  4. Use the generated types and make sure that the CRD doesn't change "too much" (massive pain: the description strings are reformatted, making the diff painful)
  5. Add the generated mapper functions and fuzz test to make sure we have coverage.
  6. Write the "core controller" using those generated types & mapper functions
  7. At some point switch the direct reconciler to be "always on"

It's a bit fuzzy right now, but this seems to be what's evolving.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this overview! Let's give this a go! 💯

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing "monitoring" about this right? Trying to be careful about creating yet another magic machine (YAMM) but do we want this to be used across direct package?

@@ -24,7 +24,7 @@ cd ${REPO_ROOT}

# Run controller-gen to generate CRDs
cd ${REPO_ROOT}/apis
go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0 object crd:crdVersions=v1,allowDangerousTypes=true output:crd:artifacts:config=config/crd/ paths="./..."
go run sigs.k8s.io/controller-tools/cmd/controller-gen@master object crd:crdVersions=v1,allowDangerousTypes=true output:crd:artifacts:config=config/crd/ paths="./..."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep this pinned ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we need a PR. I sent #1868 to add a TODO

@justinsb
Copy link
Collaborator Author

I've realized this is based on #1857

@justinsb justinsb force-pushed the monitoring_dashboard_roundtrip branch from 0047906 to 44bb4d3 Compare May 21, 2024 22:31
@justinsb
Copy link
Collaborator Author

#1857 has now merged, so rebasing. Thanks for the review @acpana!

@justinsb justinsb force-pushed the monitoring_dashboard_roundtrip branch from 44bb4d3 to 9d7ab55 Compare May 21, 2024 22:38
This allows us to see unsupported fields.
@justinsb justinsb force-pushed the monitoring_dashboard_roundtrip branch from 9d7ab55 to 3d4cb37 Compare May 21, 2024 22:49
@acpana
Copy link
Collaborator

acpana commented May 22, 2024

thanks for addressing comments 🥇

/lgtm
/approve

Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: acpana

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit b07f99c into GoogleCloudPlatform:master May 22, 2024
13 checks passed
Copy link
Collaborator

@yuwenma yuwenma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

out.Widgets = Slice_ToProto(mapCtx, in.Widgets, Widget_ToProto)
return out
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good.
Why do you comment out some lines? I saw they are NOTYET. is there any issues you hit?

krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/monitoring/v1beta1"
)

func Aggregation_FromProto(mapCtx *MapContext, in *pb.Aggregation) *krm.Aggregation {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. I think we can also include the versions, i.e. Aggregation_v1beta1_FromProto_v1

"k8s.io/klog/v2"
)

// IDEA: Load all the samples, and check that we have all the KRM paths covered
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+100. Love this direction.

@yuwenma yuwenma added this to the 1.118 milestone Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants