From f6d12b1eefc320d8aa1c16c245887cbb0798460c Mon Sep 17 00:00:00 2001 From: Akshay Shah Date: Thu, 6 Jul 2023 09:27:00 -0700 Subject: [PATCH 1/4] Handle HTTP 304s when setting span status If the RPC is using the Connect protocol and returns a not modified error, we shouldn't set the span status to error. --- interceptor.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/interceptor.go b/interceptor.go index 574e9aa..4bcb22b 100644 --- a/interceptor.go +++ b/interceptor.go @@ -159,7 +159,7 @@ func (i *Interceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc { ), ) attributes = attributeFilter(req, attributes...) - span.SetStatus(spanStatus(err)) + span.SetStatus(spanStatus(protocol, err)) span.SetAttributes(attributes...) instrumentation.duration.Record(ctx, i.config.now().Sub(requestStartTime).Milliseconds(), metric.WithAttributes(attributes...)) instrumentation.requestSize.Record(ctx, int64(requestSize), metric.WithAttributes(attributes...)) @@ -234,7 +234,7 @@ func (i *Interceptor) WrapStreamingClient(next connect.StreamingClientFunc) conn } span.SetAttributes(state.attributes...) span.SetAttributes(headerAttributes(protocol, responseKey, conn.ResponseHeader(), i.config.responseHeaderKeys)...) - span.SetStatus(spanStatus(state.error)) + span.SetStatus(spanStatus(protocol, state.error)) span.End() instrumentation.duration.Record(ctx, i.config.now().Sub(requestStartTime).Milliseconds(), metric.WithAttributes(state.attributes...)) }, @@ -317,7 +317,7 @@ func (i *Interceptor) WrapStreamingHandler(next connect.StreamingHandlerFunc) co } span.SetAttributes(state.attributes...) span.SetAttributes(headerAttributes(protocol, responseKey, conn.ResponseHeader(), i.config.responseHeaderKeys)...) - span.SetStatus(spanStatus(err)) + span.SetStatus(spanStatus(protocol, err)) instrumentation.duration.Record(ctx, i.config.now().Sub(requestStartTime).Milliseconds(), metric.WithAttributes(state.attributes...)) return err } @@ -336,10 +336,13 @@ func protocolToSemConv(protocol string) string { } } -func spanStatus(err error) (codes.Code, string) { +func spanStatus(protocol string, err error) (codes.Code, string) { if err == nil { return codes.Unset, "" } + if protocol == connectProtocol && connect.IsNotModifiedError(err) { + return codes.Unset, "" + } if connectErr := new(connect.Error); errors.As(err, &connectErr) { return codes.Error, connectErr.Message() } From 0f23772e1c79e18a04138975ff37195151b2ca1a Mon Sep 17 00:00:00 2001 From: Josh Humphries <2035234+jhump@users.noreply.github.com> Date: Thu, 6 Jul 2023 13:12:45 -0400 Subject: [PATCH 2/4] add test for not-modified error --- interceptor_test.go | 45 ++++++++ internal/gen/observability/ping/v1/ping.pb.go | 106 ++++++++++-------- .../ping/v1/pingv1connect/ping.connect.go | 49 +++++++- .../proto/observability/ping/v1/ping.proto | 8 ++ pingserver_test.go | 18 +++ 5 files changed, 171 insertions(+), 55 deletions(-) diff --git a/interceptor_test.go b/interceptor_test.go index 260e013..d6bd773 100644 --- a/interceptor_test.go +++ b/interceptor_test.go @@ -1434,6 +1434,51 @@ func TestUnaryInterceptorPropagation(t *testing.T) { assert.True(t, recordedSpan.Parent().Equal(span.SpanContext())) } +func TestUnaryInterceptorNotModifiedError(t *testing.T) { + t.Parallel() + spanRecorder := tracetest.NewSpanRecorder() + traceProvider := trace.NewTracerProvider(trace.WithSpanProcessor(spanRecorder)) + var ctx context.Context + client, _, _ := startServer( + []connect.HandlerOption{ + connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unaryFunc connect.UnaryFunc) connect.UnaryFunc { + return func(_ context.Context, request connect.AnyRequest) (connect.AnyResponse, error) { + ctx, _ = trace.NewTracerProvider().Tracer("test").Start(context.Background(), "test") + return unaryFunc(ctx, request) + } + })), + connect.WithInterceptors(NewInterceptor( + WithPropagator(propagation.TraceContext{}), + WithTracerProvider(traceProvider), + WithTrustRemote(), + )), + }, + []connect.ClientOption{ + connect.WithHTTPGet(), + }, + happyPingServer(), + ) + req := connect.NewRequest(&pingv1.PingRequest{Id: 1}) + req.Header().Set("If-None-Match", cacheablePingEtag) + _, err := client.CacheablePing(context.Background(), req) + assert.ErrorContains(t, err, "not modified") + assert.True(t, connect.IsNotModifiedError(err)) + assert.Equal(t, len(spanRecorder.Ended()), 1) + recordedSpan := spanRecorder.Ended()[0] + assert.Equal(t, codes.Unset, recordedSpan.Status().Code) + var codeAttributes []attribute.KeyValue + for _, attr := range recordedSpan.Attributes() { + if attr.Key == semconv.HTTPStatusCodeKey { + codeAttributes = append(codeAttributes, attr) + } else if strings.HasPrefix(string(attr.Key), "rpc") && strings.HasSuffix(string(attr.Key), "code") { + codeAttributes = append(codeAttributes, attr) + } + } + // should not be any RPC status attribute, only the HTTP status attribute + expectedCodeAttributes := []attribute.KeyValue{semconv.HTTPStatusCodeKey.Int(304)} + assert.Equal(t, expectedCodeAttributes, codeAttributes) +} + func TestWithUntrustedRemoteUnary(t *testing.T) { t.Parallel() var propagator propagation.TraceContext diff --git a/internal/gen/observability/ping/v1/ping.pb.go b/internal/gen/observability/ping/v1/ping.pb.go index 882e2bd..663c5bf 100644 --- a/internal/gen/observability/ping/v1/ping.pb.go +++ b/internal/gen/observability/ping/v1/ping.pb.go @@ -541,51 +541,57 @@ var file_observability_ping_v1_ping_proto_rawDesc = []byte{ 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x22, 0x0a, 0x0e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x75, - 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x32, 0xc0, 0x03, 0x0a, + 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x32, 0x9f, 0x04, 0x0a, 0x0b, 0x50, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x51, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x22, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, - 0x51, 0x0a, 0x04, 0x46, 0x61, 0x69, 0x6c, 0x12, 0x22, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, - 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, - 0x46, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x62, + 0x5d, 0x0a, 0x0d, 0x43, 0x61, 0x63, 0x68, 0x65, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x69, 0x6e, 0x67, + 0x12, 0x22, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, + 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, + 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, + 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, 0x90, 0x02, 0x01, 0x12, 0x51, + 0x0a, 0x04, 0x46, 0x61, 0x69, 0x6c, 0x12, 0x22, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, + 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, + 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x62, 0x73, + 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x50, 0x0a, 0x03, 0x53, 0x75, 0x6d, 0x12, 0x21, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, + 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x6f, 0x62, + 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x28, 0x01, 0x12, 0x5c, 0x0a, 0x07, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x12, 0x25, + 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, + 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, + 0x01, 0x12, 0x5b, 0x0a, 0x06, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x12, 0x24, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, - 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x12, 0x50, 0x0a, 0x03, 0x53, 0x75, 0x6d, 0x12, 0x21, 0x2e, 0x6f, 0x62, 0x73, 0x65, - 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, - 0x31, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x6f, - 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, - 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x28, 0x01, 0x12, 0x5c, 0x0a, 0x07, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x12, - 0x25, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, - 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, - 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, - 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x30, 0x01, 0x12, 0x5b, 0x0a, 0x06, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x12, 0x24, 0x2e, 0x6f, - 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, - 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, - 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x75, 0x6d, 0x53, 0x75, - 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, - 0xf4, 0x01, 0x0a, 0x19, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, - 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x09, 0x50, - 0x69, 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x56, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2f, - 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2d, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, - 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2d, 0x67, 0x6f, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, - 0x69, 0x74, 0x79, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x69, 0x6e, 0x67, - 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x50, 0x58, 0xaa, 0x02, 0x15, 0x4f, 0x62, 0x73, 0x65, 0x72, - 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x2e, 0x56, 0x31, - 0xca, 0x02, 0x15, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, - 0x5c, 0x50, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x21, 0x4f, 0x62, 0x73, 0x65, 0x72, - 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x5c, 0x50, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, - 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x17, 0x4f, - 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x3a, 0x3a, 0x50, 0x69, - 0x6e, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x25, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, + 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0xf4, + 0x01, 0x0a, 0x19, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, + 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x09, 0x50, 0x69, + 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x56, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x63, + 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2d, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, + 0x65, 0x74, 0x72, 0x79, 0x2d, 0x67, 0x6f, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, + 0x74, 0x79, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x69, 0x6e, 0x67, 0x76, + 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x50, 0x58, 0xaa, 0x02, 0x15, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, + 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x2e, 0x56, 0x31, 0xca, + 0x02, 0x15, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x5c, + 0x50, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x21, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, + 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x5c, 0x50, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x5c, + 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x17, 0x4f, 0x62, + 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x3a, 0x3a, 0x50, 0x69, 0x6e, + 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -615,17 +621,19 @@ var file_observability_ping_v1_ping_proto_goTypes = []interface{}{ } var file_observability_ping_v1_ping_proto_depIdxs = []int32{ 0, // 0: observability.ping.v1.PingService.Ping:input_type -> observability.ping.v1.PingRequest - 2, // 1: observability.ping.v1.PingService.Fail:input_type -> observability.ping.v1.FailRequest - 4, // 2: observability.ping.v1.PingService.Sum:input_type -> observability.ping.v1.SumRequest - 6, // 3: observability.ping.v1.PingService.CountUp:input_type -> observability.ping.v1.CountUpRequest - 8, // 4: observability.ping.v1.PingService.CumSum:input_type -> observability.ping.v1.CumSumRequest - 1, // 5: observability.ping.v1.PingService.Ping:output_type -> observability.ping.v1.PingResponse - 3, // 6: observability.ping.v1.PingService.Fail:output_type -> observability.ping.v1.FailResponse - 5, // 7: observability.ping.v1.PingService.Sum:output_type -> observability.ping.v1.SumResponse - 7, // 8: observability.ping.v1.PingService.CountUp:output_type -> observability.ping.v1.CountUpResponse - 9, // 9: observability.ping.v1.PingService.CumSum:output_type -> observability.ping.v1.CumSumResponse - 5, // [5:10] is the sub-list for method output_type - 0, // [0:5] is the sub-list for method input_type + 0, // 1: observability.ping.v1.PingService.CacheablePing:input_type -> observability.ping.v1.PingRequest + 2, // 2: observability.ping.v1.PingService.Fail:input_type -> observability.ping.v1.FailRequest + 4, // 3: observability.ping.v1.PingService.Sum:input_type -> observability.ping.v1.SumRequest + 6, // 4: observability.ping.v1.PingService.CountUp:input_type -> observability.ping.v1.CountUpRequest + 8, // 5: observability.ping.v1.PingService.CumSum:input_type -> observability.ping.v1.CumSumRequest + 1, // 6: observability.ping.v1.PingService.Ping:output_type -> observability.ping.v1.PingResponse + 1, // 7: observability.ping.v1.PingService.CacheablePing:output_type -> observability.ping.v1.PingResponse + 3, // 8: observability.ping.v1.PingService.Fail:output_type -> observability.ping.v1.FailResponse + 5, // 9: observability.ping.v1.PingService.Sum:output_type -> observability.ping.v1.SumResponse + 7, // 10: observability.ping.v1.PingService.CountUp:output_type -> observability.ping.v1.CountUpResponse + 9, // 11: observability.ping.v1.PingService.CumSum:output_type -> observability.ping.v1.CumSumResponse + 6, // [6:12] is the sub-list for method output_type + 0, // [0:6] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name diff --git a/internal/gen/observability/ping/v1/pingv1connect/ping.connect.go b/internal/gen/observability/ping/v1/pingv1connect/ping.connect.go index acf4877..7588f46 100644 --- a/internal/gen/observability/ping/v1/pingv1connect/ping.connect.go +++ b/internal/gen/observability/ping/v1/pingv1connect/ping.connect.go @@ -32,7 +32,7 @@ import ( // generated with a version of connect newer than the one compiled into your binary. You can fix the // problem by either regenerating this code with an older version of connect or updating the connect // version compiled into your binary. -const _ = connect_go.IsAtLeastVersion0_1_0 +const _ = connect_go.IsAtLeastVersion1_7_0 const ( // PingServiceName is the fully-qualified name of the PingService service. @@ -49,6 +49,9 @@ const ( const ( // PingServicePingProcedure is the fully-qualified name of the PingService's Ping RPC. PingServicePingProcedure = "/observability.ping.v1.PingService/Ping" + // PingServiceCacheablePingProcedure is the fully-qualified name of the PingService's CacheablePing + // RPC. + PingServiceCacheablePingProcedure = "/observability.ping.v1.PingService/CacheablePing" // PingServiceFailProcedure is the fully-qualified name of the PingService's Fail RPC. PingServiceFailProcedure = "/observability.ping.v1.PingService/Fail" // PingServiceSumProcedure is the fully-qualified name of the PingService's Sum RPC. @@ -63,6 +66,12 @@ const ( type PingServiceClient interface { // Ping sends a ping to the server to determine if it's reachable. Ping(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) + // CacheablePing sends a ping request and returns a cacheable ping + // response. This endpoint supports conditional GETs. Responses + // to GET requests will include an Etag header that can be used + // to conditionally check for a newer response in a subsequent + // request. + CacheablePing(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) // Fail always fails. Fail(context.Context, *connect_go.Request[v1.FailRequest]) (*connect_go.Response[v1.FailResponse], error) // Sum calculates the sum of the numbers sent on the stream. @@ -88,6 +97,12 @@ func NewPingServiceClient(httpClient connect_go.HTTPClient, baseURL string, opts baseURL+PingServicePingProcedure, opts..., ), + cacheablePing: connect_go.NewClient[v1.PingRequest, v1.PingResponse]( + httpClient, + baseURL+PingServiceCacheablePingProcedure, + connect_go.WithIdempotency(connect_go.IdempotencyNoSideEffects), + connect_go.WithClientOptions(opts...), + ), fail: connect_go.NewClient[v1.FailRequest, v1.FailResponse]( httpClient, baseURL+PingServiceFailProcedure, @@ -113,11 +128,12 @@ func NewPingServiceClient(httpClient connect_go.HTTPClient, baseURL string, opts // pingServiceClient implements PingServiceClient. type pingServiceClient struct { - ping *connect_go.Client[v1.PingRequest, v1.PingResponse] - fail *connect_go.Client[v1.FailRequest, v1.FailResponse] - sum *connect_go.Client[v1.SumRequest, v1.SumResponse] - countUp *connect_go.Client[v1.CountUpRequest, v1.CountUpResponse] - cumSum *connect_go.Client[v1.CumSumRequest, v1.CumSumResponse] + ping *connect_go.Client[v1.PingRequest, v1.PingResponse] + cacheablePing *connect_go.Client[v1.PingRequest, v1.PingResponse] + fail *connect_go.Client[v1.FailRequest, v1.FailResponse] + sum *connect_go.Client[v1.SumRequest, v1.SumResponse] + countUp *connect_go.Client[v1.CountUpRequest, v1.CountUpResponse] + cumSum *connect_go.Client[v1.CumSumRequest, v1.CumSumResponse] } // Ping calls observability.ping.v1.PingService.Ping. @@ -125,6 +141,11 @@ func (c *pingServiceClient) Ping(ctx context.Context, req *connect_go.Request[v1 return c.ping.CallUnary(ctx, req) } +// CacheablePing calls observability.ping.v1.PingService.CacheablePing. +func (c *pingServiceClient) CacheablePing(ctx context.Context, req *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) { + return c.cacheablePing.CallUnary(ctx, req) +} + // Fail calls observability.ping.v1.PingService.Fail. func (c *pingServiceClient) Fail(ctx context.Context, req *connect_go.Request[v1.FailRequest]) (*connect_go.Response[v1.FailResponse], error) { return c.fail.CallUnary(ctx, req) @@ -149,6 +170,12 @@ func (c *pingServiceClient) CumSum(ctx context.Context) *connect_go.BidiStreamFo type PingServiceHandler interface { // Ping sends a ping to the server to determine if it's reachable. Ping(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) + // CacheablePing sends a ping request and returns a cacheable ping + // response. This endpoint supports conditional GETs. Responses + // to GET requests will include an Etag header that can be used + // to conditionally check for a newer response in a subsequent + // request. + CacheablePing(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) // Fail always fails. Fail(context.Context, *connect_go.Request[v1.FailRequest]) (*connect_go.Response[v1.FailResponse], error) // Sum calculates the sum of the numbers sent on the stream. @@ -171,6 +198,12 @@ func NewPingServiceHandler(svc PingServiceHandler, opts ...connect_go.HandlerOpt svc.Ping, opts..., )) + mux.Handle(PingServiceCacheablePingProcedure, connect_go.NewUnaryHandler( + PingServiceCacheablePingProcedure, + svc.CacheablePing, + connect_go.WithIdempotency(connect_go.IdempotencyNoSideEffects), + connect_go.WithHandlerOptions(opts...), + )) mux.Handle(PingServiceFailProcedure, connect_go.NewUnaryHandler( PingServiceFailProcedure, svc.Fail, @@ -201,6 +234,10 @@ func (UnimplementedPingServiceHandler) Ping(context.Context, *connect_go.Request return nil, connect_go.NewError(connect_go.CodeUnimplemented, errors.New("observability.ping.v1.PingService.Ping is not implemented")) } +func (UnimplementedPingServiceHandler) CacheablePing(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) { + return nil, connect_go.NewError(connect_go.CodeUnimplemented, errors.New("observability.ping.v1.PingService.CacheablePing is not implemented")) +} + func (UnimplementedPingServiceHandler) Fail(context.Context, *connect_go.Request[v1.FailRequest]) (*connect_go.Response[v1.FailResponse], error) { return nil, connect_go.NewError(connect_go.CodeUnimplemented, errors.New("observability.ping.v1.PingService.Fail is not implemented")) } diff --git a/internal/proto/observability/ping/v1/ping.proto b/internal/proto/observability/ping/v1/ping.proto index 8ce1e41..9bdba6d 100644 --- a/internal/proto/observability/ping/v1/ping.proto +++ b/internal/proto/observability/ping/v1/ping.proto @@ -59,6 +59,14 @@ message CumSumResponse { service PingService { // Ping sends a ping to the server to determine if it's reachable. rpc Ping(PingRequest) returns (PingResponse) {} + // CacheablePing sends a ping request and returns a cacheable ping + // response. This endpoint supports conditional GETs. Responses + // to GET requests will include an Etag header that can be used + // to conditionally check for a newer response in a subsequent + // request. + rpc CacheablePing(PingRequest) returns (PingResponse) { + option idempotency_level = NO_SIDE_EFFECTS; + } // Fail always fails. rpc Fail(FailRequest) returns (FailResponse) {} // Sum calculates the sum of the numbers sent on the stream. diff --git a/pingserver_test.go b/pingserver_test.go index 6d53e78..e9e4cf2 100644 --- a/pingserver_test.go +++ b/pingserver_test.go @@ -19,12 +19,15 @@ import ( "errors" "fmt" "io" + "net/http" "github.com/bufbuild/connect-go" pingv1 "github.com/bufbuild/connect-opentelemetry-go/internal/gen/observability/ping/v1" "github.com/bufbuild/connect-opentelemetry-go/internal/gen/observability/ping/v1/pingv1connect" ) +const cacheablePingEtag = "ABCDEFGH" + func pingHappy(_ context.Context, req *connect.Request[pingv1.PingRequest]) (*connect.Response[pingv1.PingResponse], error) { return connect.NewResponse(&pingv1.PingResponse{ Id: req.Msg.Id, @@ -106,6 +109,21 @@ func (p *pluggablePingServer) Ping( return p.ping(ctx, request) } +func (p *pluggablePingServer) CacheablePing( + ctx context.Context, + request *connect.Request[pingv1.PingRequest], +) (*connect.Response[pingv1.PingResponse], error) { + if request.HTTPMethod() == http.MethodGet && request.Header().Get("If-None-Match") == cacheablePingEtag { + return nil, connect.NewNotModifiedError(nil) + } + resp, err := p.ping(ctx, request) + if err != nil { + return nil, err + } + resp.Header().Set("Etag", cacheablePingEtag) + return resp, nil +} + func (p *pluggablePingServer) CumSum( ctx context.Context, stream *connect.BidiStream[pingv1.CumSumRequest, pingv1.CumSumResponse], From 16486f56f6c6ddecd2ce20077cd652242ab3f5d1 Mon Sep 17 00:00:00 2001 From: Josh Humphries <2035234+jhump@users.noreply.github.com> Date: Thu, 6 Jul 2023 13:15:26 -0400 Subject: [PATCH 3/4] add exclusions for CacheablePing --- internal/proto/buf.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/proto/buf.yaml b/internal/proto/buf.yaml index efda402..88ed742 100644 --- a/internal/proto/buf.yaml +++ b/internal/proto/buf.yaml @@ -2,6 +2,10 @@ version: v1 lint: use: - DEFAULT + except: + - RPC_REQUEST_STANDARD_NAME + - RPC_RESPONSE_STANDARD_NAME + - RPC_REQUEST_RESPONSE_UNIQUE breaking: use: - WIRE_JSON From 4d0ae9f5f0252a2be10dbc0362bc8d3b2f5f0c6c Mon Sep 17 00:00:00 2001 From: Akshay Shah Date: Fri, 7 Jul 2023 14:38:34 -0700 Subject: [PATCH 4/4] Make Ping idempotent, remove CacheablePing --- interceptor_test.go | 2 +- internal/gen/observability/ping/v1/ping.pb.go | 109 ++++++++---------- .../ping/v1/pingv1connect/ping.connect.go | 45 +------- internal/proto/buf.yaml | 4 - .../proto/observability/ping/v1/ping.proto | 8 +- pingserver_test.go | 7 -- 6 files changed, 58 insertions(+), 117 deletions(-) diff --git a/interceptor_test.go b/interceptor_test.go index d6bd773..5338b6f 100644 --- a/interceptor_test.go +++ b/interceptor_test.go @@ -1460,7 +1460,7 @@ func TestUnaryInterceptorNotModifiedError(t *testing.T) { ) req := connect.NewRequest(&pingv1.PingRequest{Id: 1}) req.Header().Set("If-None-Match", cacheablePingEtag) - _, err := client.CacheablePing(context.Background(), req) + _, err := client.Ping(context.Background(), req) assert.ErrorContains(t, err, "not modified") assert.True(t, connect.IsNotModifiedError(err)) assert.Equal(t, len(spanRecorder.Ended()), 1) diff --git a/internal/gen/observability/ping/v1/ping.pb.go b/internal/gen/observability/ping/v1/ping.pb.go index 663c5bf..cea3421 100644 --- a/internal/gen/observability/ping/v1/ping.pb.go +++ b/internal/gen/observability/ping/v1/ping.pb.go @@ -541,57 +541,52 @@ var file_observability_ping_v1_ping_proto_rawDesc = []byte{ 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x22, 0x0a, 0x0e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x75, - 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x32, 0x9f, 0x04, 0x0a, - 0x0b, 0x50, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x51, 0x0a, 0x04, + 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x32, 0xc3, 0x03, 0x0a, + 0x0b, 0x50, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x54, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x22, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, - 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, - 0x5d, 0x0a, 0x0d, 0x43, 0x61, 0x63, 0x68, 0x65, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x69, 0x6e, 0x67, - 0x12, 0x22, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, - 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, - 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, - 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, 0x90, 0x02, 0x01, 0x12, 0x51, - 0x0a, 0x04, 0x46, 0x61, 0x69, 0x6c, 0x12, 0x22, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, - 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, - 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x62, 0x73, + 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, 0x90, + 0x02, 0x01, 0x12, 0x51, 0x0a, 0x04, 0x46, 0x61, 0x69, 0x6c, 0x12, 0x22, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, - 0x76, 0x31, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x00, 0x12, 0x50, 0x0a, 0x03, 0x53, 0x75, 0x6d, 0x12, 0x21, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, - 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, - 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x6f, 0x62, - 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, - 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x00, 0x28, 0x01, 0x12, 0x5c, 0x0a, 0x07, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x12, 0x25, + 0x76, 0x31, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, - 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, - 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, - 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, - 0x01, 0x12, 0x5b, 0x0a, 0x06, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x12, 0x24, 0x2e, 0x6f, 0x62, - 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, - 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x25, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, - 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0xf4, - 0x01, 0x0a, 0x19, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, - 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x09, 0x50, 0x69, - 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x56, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x63, - 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2d, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, - 0x65, 0x74, 0x72, 0x79, 0x2d, 0x67, 0x6f, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, - 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, - 0x74, 0x79, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x69, 0x6e, 0x67, 0x76, - 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x50, 0x58, 0xaa, 0x02, 0x15, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, - 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x2e, 0x56, 0x31, 0xca, - 0x02, 0x15, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x5c, - 0x50, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x21, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, - 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x5c, 0x50, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x5c, - 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x17, 0x4f, 0x62, - 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x3a, 0x3a, 0x50, 0x69, 0x6e, - 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x50, 0x0a, 0x03, 0x53, 0x75, 0x6d, 0x12, 0x21, 0x2e, 0x6f, + 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x22, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, + 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x12, 0x5c, 0x0a, 0x07, 0x43, 0x6f, 0x75, 0x6e, 0x74, + 0x55, 0x70, 0x12, 0x25, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, + 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, + 0x55, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x6f, 0x62, 0x73, 0x65, + 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x5b, 0x0a, 0x06, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x12, + 0x24, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, + 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, + 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x75, + 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, + 0x30, 0x01, 0x42, 0xf4, 0x01, 0x0a, 0x19, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, + 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x42, 0x09, 0x50, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x56, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, 0x69, + 0x6c, 0x64, 0x2f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2d, 0x6f, 0x70, 0x65, 0x6e, 0x74, + 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2d, 0x67, 0x6f, 0x2f, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, + 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x70, + 0x69, 0x6e, 0x67, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x50, 0x58, 0xaa, 0x02, 0x15, 0x4f, 0x62, + 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x50, 0x69, 0x6e, 0x67, + 0x2e, 0x56, 0x31, 0xca, 0x02, 0x15, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, + 0x69, 0x74, 0x79, 0x5c, 0x50, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x21, 0x4f, 0x62, + 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x5c, 0x50, 0x69, 0x6e, 0x67, + 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, + 0x02, 0x17, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x3a, + 0x3a, 0x50, 0x69, 0x6e, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -621,19 +616,17 @@ var file_observability_ping_v1_ping_proto_goTypes = []interface{}{ } var file_observability_ping_v1_ping_proto_depIdxs = []int32{ 0, // 0: observability.ping.v1.PingService.Ping:input_type -> observability.ping.v1.PingRequest - 0, // 1: observability.ping.v1.PingService.CacheablePing:input_type -> observability.ping.v1.PingRequest - 2, // 2: observability.ping.v1.PingService.Fail:input_type -> observability.ping.v1.FailRequest - 4, // 3: observability.ping.v1.PingService.Sum:input_type -> observability.ping.v1.SumRequest - 6, // 4: observability.ping.v1.PingService.CountUp:input_type -> observability.ping.v1.CountUpRequest - 8, // 5: observability.ping.v1.PingService.CumSum:input_type -> observability.ping.v1.CumSumRequest - 1, // 6: observability.ping.v1.PingService.Ping:output_type -> observability.ping.v1.PingResponse - 1, // 7: observability.ping.v1.PingService.CacheablePing:output_type -> observability.ping.v1.PingResponse - 3, // 8: observability.ping.v1.PingService.Fail:output_type -> observability.ping.v1.FailResponse - 5, // 9: observability.ping.v1.PingService.Sum:output_type -> observability.ping.v1.SumResponse - 7, // 10: observability.ping.v1.PingService.CountUp:output_type -> observability.ping.v1.CountUpResponse - 9, // 11: observability.ping.v1.PingService.CumSum:output_type -> observability.ping.v1.CumSumResponse - 6, // [6:12] is the sub-list for method output_type - 0, // [0:6] is the sub-list for method input_type + 2, // 1: observability.ping.v1.PingService.Fail:input_type -> observability.ping.v1.FailRequest + 4, // 2: observability.ping.v1.PingService.Sum:input_type -> observability.ping.v1.SumRequest + 6, // 3: observability.ping.v1.PingService.CountUp:input_type -> observability.ping.v1.CountUpRequest + 8, // 4: observability.ping.v1.PingService.CumSum:input_type -> observability.ping.v1.CumSumRequest + 1, // 5: observability.ping.v1.PingService.Ping:output_type -> observability.ping.v1.PingResponse + 3, // 6: observability.ping.v1.PingService.Fail:output_type -> observability.ping.v1.FailResponse + 5, // 7: observability.ping.v1.PingService.Sum:output_type -> observability.ping.v1.SumResponse + 7, // 8: observability.ping.v1.PingService.CountUp:output_type -> observability.ping.v1.CountUpResponse + 9, // 9: observability.ping.v1.PingService.CumSum:output_type -> observability.ping.v1.CumSumResponse + 5, // [5:10] is the sub-list for method output_type + 0, // [0:5] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name diff --git a/internal/gen/observability/ping/v1/pingv1connect/ping.connect.go b/internal/gen/observability/ping/v1/pingv1connect/ping.connect.go index 7588f46..3af6750 100644 --- a/internal/gen/observability/ping/v1/pingv1connect/ping.connect.go +++ b/internal/gen/observability/ping/v1/pingv1connect/ping.connect.go @@ -49,9 +49,6 @@ const ( const ( // PingServicePingProcedure is the fully-qualified name of the PingService's Ping RPC. PingServicePingProcedure = "/observability.ping.v1.PingService/Ping" - // PingServiceCacheablePingProcedure is the fully-qualified name of the PingService's CacheablePing - // RPC. - PingServiceCacheablePingProcedure = "/observability.ping.v1.PingService/CacheablePing" // PingServiceFailProcedure is the fully-qualified name of the PingService's Fail RPC. PingServiceFailProcedure = "/observability.ping.v1.PingService/Fail" // PingServiceSumProcedure is the fully-qualified name of the PingService's Sum RPC. @@ -66,12 +63,6 @@ const ( type PingServiceClient interface { // Ping sends a ping to the server to determine if it's reachable. Ping(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) - // CacheablePing sends a ping request and returns a cacheable ping - // response. This endpoint supports conditional GETs. Responses - // to GET requests will include an Etag header that can be used - // to conditionally check for a newer response in a subsequent - // request. - CacheablePing(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) // Fail always fails. Fail(context.Context, *connect_go.Request[v1.FailRequest]) (*connect_go.Response[v1.FailResponse], error) // Sum calculates the sum of the numbers sent on the stream. @@ -95,11 +86,6 @@ func NewPingServiceClient(httpClient connect_go.HTTPClient, baseURL string, opts ping: connect_go.NewClient[v1.PingRequest, v1.PingResponse]( httpClient, baseURL+PingServicePingProcedure, - opts..., - ), - cacheablePing: connect_go.NewClient[v1.PingRequest, v1.PingResponse]( - httpClient, - baseURL+PingServiceCacheablePingProcedure, connect_go.WithIdempotency(connect_go.IdempotencyNoSideEffects), connect_go.WithClientOptions(opts...), ), @@ -128,12 +114,11 @@ func NewPingServiceClient(httpClient connect_go.HTTPClient, baseURL string, opts // pingServiceClient implements PingServiceClient. type pingServiceClient struct { - ping *connect_go.Client[v1.PingRequest, v1.PingResponse] - cacheablePing *connect_go.Client[v1.PingRequest, v1.PingResponse] - fail *connect_go.Client[v1.FailRequest, v1.FailResponse] - sum *connect_go.Client[v1.SumRequest, v1.SumResponse] - countUp *connect_go.Client[v1.CountUpRequest, v1.CountUpResponse] - cumSum *connect_go.Client[v1.CumSumRequest, v1.CumSumResponse] + ping *connect_go.Client[v1.PingRequest, v1.PingResponse] + fail *connect_go.Client[v1.FailRequest, v1.FailResponse] + sum *connect_go.Client[v1.SumRequest, v1.SumResponse] + countUp *connect_go.Client[v1.CountUpRequest, v1.CountUpResponse] + cumSum *connect_go.Client[v1.CumSumRequest, v1.CumSumResponse] } // Ping calls observability.ping.v1.PingService.Ping. @@ -141,11 +126,6 @@ func (c *pingServiceClient) Ping(ctx context.Context, req *connect_go.Request[v1 return c.ping.CallUnary(ctx, req) } -// CacheablePing calls observability.ping.v1.PingService.CacheablePing. -func (c *pingServiceClient) CacheablePing(ctx context.Context, req *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) { - return c.cacheablePing.CallUnary(ctx, req) -} - // Fail calls observability.ping.v1.PingService.Fail. func (c *pingServiceClient) Fail(ctx context.Context, req *connect_go.Request[v1.FailRequest]) (*connect_go.Response[v1.FailResponse], error) { return c.fail.CallUnary(ctx, req) @@ -170,12 +150,6 @@ func (c *pingServiceClient) CumSum(ctx context.Context) *connect_go.BidiStreamFo type PingServiceHandler interface { // Ping sends a ping to the server to determine if it's reachable. Ping(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) - // CacheablePing sends a ping request and returns a cacheable ping - // response. This endpoint supports conditional GETs. Responses - // to GET requests will include an Etag header that can be used - // to conditionally check for a newer response in a subsequent - // request. - CacheablePing(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) // Fail always fails. Fail(context.Context, *connect_go.Request[v1.FailRequest]) (*connect_go.Response[v1.FailResponse], error) // Sum calculates the sum of the numbers sent on the stream. @@ -196,11 +170,6 @@ func NewPingServiceHandler(svc PingServiceHandler, opts ...connect_go.HandlerOpt mux.Handle(PingServicePingProcedure, connect_go.NewUnaryHandler( PingServicePingProcedure, svc.Ping, - opts..., - )) - mux.Handle(PingServiceCacheablePingProcedure, connect_go.NewUnaryHandler( - PingServiceCacheablePingProcedure, - svc.CacheablePing, connect_go.WithIdempotency(connect_go.IdempotencyNoSideEffects), connect_go.WithHandlerOptions(opts...), )) @@ -234,10 +203,6 @@ func (UnimplementedPingServiceHandler) Ping(context.Context, *connect_go.Request return nil, connect_go.NewError(connect_go.CodeUnimplemented, errors.New("observability.ping.v1.PingService.Ping is not implemented")) } -func (UnimplementedPingServiceHandler) CacheablePing(context.Context, *connect_go.Request[v1.PingRequest]) (*connect_go.Response[v1.PingResponse], error) { - return nil, connect_go.NewError(connect_go.CodeUnimplemented, errors.New("observability.ping.v1.PingService.CacheablePing is not implemented")) -} - func (UnimplementedPingServiceHandler) Fail(context.Context, *connect_go.Request[v1.FailRequest]) (*connect_go.Response[v1.FailResponse], error) { return nil, connect_go.NewError(connect_go.CodeUnimplemented, errors.New("observability.ping.v1.PingService.Fail is not implemented")) } diff --git a/internal/proto/buf.yaml b/internal/proto/buf.yaml index 88ed742..efda402 100644 --- a/internal/proto/buf.yaml +++ b/internal/proto/buf.yaml @@ -2,10 +2,6 @@ version: v1 lint: use: - DEFAULT - except: - - RPC_REQUEST_STANDARD_NAME - - RPC_RESPONSE_STANDARD_NAME - - RPC_REQUEST_RESPONSE_UNIQUE breaking: use: - WIRE_JSON diff --git a/internal/proto/observability/ping/v1/ping.proto b/internal/proto/observability/ping/v1/ping.proto index 9bdba6d..40f802c 100644 --- a/internal/proto/observability/ping/v1/ping.proto +++ b/internal/proto/observability/ping/v1/ping.proto @@ -58,13 +58,7 @@ message CumSumResponse { service PingService { // Ping sends a ping to the server to determine if it's reachable. - rpc Ping(PingRequest) returns (PingResponse) {} - // CacheablePing sends a ping request and returns a cacheable ping - // response. This endpoint supports conditional GETs. Responses - // to GET requests will include an Etag header that can be used - // to conditionally check for a newer response in a subsequent - // request. - rpc CacheablePing(PingRequest) returns (PingResponse) { + rpc Ping(PingRequest) returns (PingResponse) { option idempotency_level = NO_SIDE_EFFECTS; } // Fail always fails. diff --git a/pingserver_test.go b/pingserver_test.go index e9e4cf2..dcf2c47 100644 --- a/pingserver_test.go +++ b/pingserver_test.go @@ -105,13 +105,6 @@ type pluggablePingServer struct { func (p *pluggablePingServer) Ping( ctx context.Context, request *connect.Request[pingv1.PingRequest], -) (*connect.Response[pingv1.PingResponse], error) { - return p.ping(ctx, request) -} - -func (p *pluggablePingServer) CacheablePing( - ctx context.Context, - request *connect.Request[pingv1.PingRequest], ) (*connect.Response[pingv1.PingResponse], error) { if request.HTTPMethod() == http.MethodGet && request.Header().Get("If-None-Match") == cacheablePingEtag { return nil, connect.NewNotModifiedError(nil)