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

protovalidate: support new protovalidate-go Validator interface #746

Merged

Conversation

zchee
Copy link
Contributor

@zchee zchee commented Feb 3, 2025

Changes

protovalidate: support new protovalidate-go Validator interface.

Verification

protovalidate-go v0.9 release said:

protovalidate.Validator is now an intkerface and not a struct. Pointers of type *protovalidate.Validator should be changed to protovalidate.Validator values instead.

@zchee zchee force-pushed the support-protovalidate-go-0.9 branch 2 times, most recently from 21dd301 to 8cd57e5 Compare February 3, 2025 12:32
@zchee zchee force-pushed the support-protovalidate-go-0.9 branch from 8cd57e5 to d89418e Compare February 3, 2025 12:39
@zchee
Copy link
Contributor Author

zchee commented Feb 3, 2025

Why make all have the below diff?

diff --git a/README.md b/README.md
index 8c4ac16..c923991 100644
--- a/README.md
+++ b/README.md
@@ -17,22 +17,22 @@ ## Middleware
 Additional great feature of interceptors is the fact we can chain those. For example below you can find example server side chain of interceptors with full observabiliy correlation, auth and panic recovery:
 
 ```go mdox-exec="sed -n '136,151p' examples/server/main.go"
-	grpcSrv := grpc.NewServer(
-		grpc.ChainUnaryInterceptor(
-			// Order matters e.g. tracing interceptor have to create span first for the later exemplars to work.
-			otelgrpc.UnaryServerInterceptor(),
-			srvMetrics.UnaryServerInterceptor(grpcprom.WithExemplarFromContext(exemplarFromContext)),
-			logging.UnaryServerInterceptor(interceptorLogger(rpcLogger), logging.WithFieldsFromContext(logTraceID)),
-			selector.UnaryServerInterceptor(auth.UnaryServerInterceptor(authFn), selector.MatchFunc(allButHealthZ)),
-			recovery.UnaryServerInterceptor(recovery.WithRecoveryHandler(grpcPanicRecoveryHandler)),
-		),
-		grpc.ChainStreamInterceptor(
-			otelgrpc.StreamServerInterceptor(),
-			srvMetrics.StreamServerInterceptor(grpcprom.WithExemplarFromContext(exemplarFromContext)),
-			logging.StreamServerInterceptor(interceptorLogger(rpcLogger), logging.WithFieldsFromContext(logTraceID)),
-			selector.StreamServerInterceptor(auth.StreamServerInterceptor(authFn), selector.MatchFunc(allButHealthZ)),
-			recovery.StreamServerInterceptor(recovery.WithRecoveryHandler(grpcPanicRecoveryHandler)),
-		),
+	)
+	t := &testpb.TestPingService{}
+	testpb.RegisterTestServiceServer(grpcSrv, t)
+	srvMetrics.InitializeMetrics(grpcSrv)
+
+	g := &run.Group{}
+	g.Add(func() error {
+		l, err := net.Listen("tcp", grpcAddr)
+		if err != nil {
+			return err
+		}
+		logger.Info("starting gRPC server", "addr", l.Addr().String())
+		return grpcSrv.Serve(l)
+	}, func(err error) {
+		grpcSrv.GracefulStop()
+		grpcSrv.Stop()

This pattern offers clean and explicit shared functionality for all your gRPC methods. Full, buildable examples can be found in examples directory.

@charlieparkes-Q
Copy link

charlieparkes-Q commented Feb 3, 2025

Would love to get this version upgrade merged as it's blocking package upgrades on our projects. protovalidate-go v0.8 and v0.9 broke compatibility, and was fixed with v0.9.1. bufbuild/protovalidate-go#180 (comment)

Comment on lines +3 to +5
go 1.21.1

toolchain go1.21.13
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert these changes, as a library we should not specify subversions of the Go version. See grpc/grpc-go#7831.

Copy link
Contributor Author

@zchee zchee Feb 9, 2025

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please re-revert it and we can figure out the CI failure. CI is unstable as it is, don't trust it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks. Clearly we still need to run go mod tidy, and clearly that introduces the toolchain directive (and minor version requirement). Could you try to figure out which of the upgrades here is introducing the toolchain directive? It shouldn't be added just on its own.

Copy link
Contributor Author

@zchee zchee Feb 11, 2025

Choose a reason for hiding this comment

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

@johanbrandhorst This issue not related to upgrade protovalidate-go. I think should be separate PR or issue and fix until next release if you want (I don't want do it at this PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you saying that the toolchain is being added when running go mod tidy on main? I think this is the first time we've seen it.

Copy link
Contributor Author

@zchee zchee Feb 11, 2025

Choose a reason for hiding this comment

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

No, as I said on #746 (comment), it seems to be related to:

From the updated go.mod, the cel.dev/expr has a toolchain directive:

I don't know which is the root cause.


Could you try to figure out ...

Several developers are already waiting for this PR via emoji action. The go-grpc-middleware maintainers are concerned about the issue of the "toolcahin" directive in go.mod due to go-grpc-ecosystem policy, but users (including me) just want to upgrade the protovalidate-go. Those are separate issues, and the main branch is not stable, so if the concerns about the toolchain directive take precedence, please ensure the maintainers understand and resolve those issues, then upgrade the protovalidate-go by maintainers until the next release. Please feel free to close this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

cel-spec does seems to be the culprit. I think it's fair to say that we could merge this with the new toolchain directive if we can plan to remove it again before the next release. We'd need to create an issue with cel-spec to get them to remove their spec (or potentially look into their dependencies which may have forced its addition). In any case, if you'd like to just run go mod tidy in this PR and push that, we can get this upgrade merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

testing/testpb/test.pb.go Outdated Show resolved Hide resolved
@zchee zchee force-pushed the support-protovalidate-go-0.9 branch from 50d28b3 to 1a6bb90 Compare February 9, 2025 15:00
@zchee zchee force-pushed the support-protovalidate-go-0.9 branch from 1a6bb90 to f99b389 Compare February 9, 2025 15:04
@zchee
Copy link
Contributor Author

zchee commented Feb 9, 2025

@johanbrandhorst
Revert regenerate pb, not revert go.mod change because commented cause. Related grpc/grpc-go#7831 (comment) ?
Also, still failed lint job:

PTAL.

@zchee zchee requested a review from johanbrandhorst February 9, 2025 15:11
This reverts commit 7ba0f46.

Signed-off-by: Koichi Shiraishi <[email protected]>
@zchee
Copy link
Contributor Author

zchee commented Feb 11, 2025

@johanbrandhorst
Another issue occurred:

Error: This request has been automatically failed because it uses a deprecated version of `actions/cache: v1`. Please update your workflow to use v3/v4 of actions/cache to avoid interruptions.
Learn more: https://github.blog/changelog/2024-12-05-notice-of-upcoming-releases-and-breaking-changes-for-github-actions/#actions-cache-v1-v2-and-actions-toolkit-cache-package-closing-down

@johanbrandhorst
Copy link
Collaborator

Yeah these just started happening, I'll get that fixed separately.

@johanbrandhorst johanbrandhorst merged commit c6f3545 into grpc-ecosystem:main Feb 11, 2025
0 of 7 checks passed
@zchee zchee deleted the support-protovalidate-go-0.9 branch February 11, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants