From 70e1cf5dedba5ac032153d0c7831b7866ff14a93 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 01:51:06 +0000 Subject: [PATCH 1/2] build(deps): bump github.com/ogen-go/ogen from 0.73.0 to 0.74.0 Bumps [github.com/ogen-go/ogen](https://github.com/ogen-go/ogen) from 0.73.0 to 0.74.0. - [Release notes](https://github.com/ogen-go/ogen/releases) - [Commits](https://github.com/ogen-go/ogen/compare/v0.73.0...v0.74.0) --- updated-dependencies: - dependency-name: github.com/ogen-go/ogen dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9c7b0215..996c7f96 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/go-faster/tcpproxy v0.1.0 github.com/go-logfmt/logfmt v0.6.0 github.com/google/uuid v1.3.1 - github.com/ogen-go/ogen v0.73.0 + github.com/ogen-go/ogen v0.74.0 github.com/opentracing/opentracing-go v1.2.0 github.com/prometheus/common v0.44.0 github.com/prometheus/prometheus v0.47.0 diff --git a/go.sum b/go.sum index c0cde88f..3e2f1d55 100644 --- a/go.sum +++ b/go.sum @@ -370,8 +370,8 @@ github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/npillmayer/nestext v0.1.3/go.mod h1:h2lrijH8jpicr25dFY+oAJLyzlya6jhnuG+zWp9L0Uk= -github.com/ogen-go/ogen v0.73.0 h1:h9HFV2V/h7UTKewlJpvOjx0gHIjjn4O9mjKe3eLNWkY= -github.com/ogen-go/ogen v0.73.0/go.mod h1:CS1RfTfLLcxw968GF2pEw8r6P6YTlU+mCOTGJvl7P2c= +github.com/ogen-go/ogen v0.74.0 h1:EFzCDm9h7RupLMn4RAEC1kIjXa9KUJTLGkMyejVmB34= +github.com/ogen-go/ogen v0.74.0/go.mod h1:Jr2HmdCICrlXw+29Vcx1EAgx4dIQpXEwCpwuIDqrj6Y= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= From 7bf10201d0eb56940e437c9f93993f8fd9c294f4 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Thu, 14 Sep 2023 18:52:42 +0300 Subject: [PATCH 2/2] chore: commit generated files --- internal/lokiapi/oas_client_gen.go | 13 ++ internal/lokiapi/oas_handlers_gen.go | 78 +++++--- internal/lokiapi/oas_response_encoders_gen.go | 11 ++ internal/lokiapi/oas_schemas_gen.go | 8 + internal/promapi/oas_client_gen.go | 27 +++ internal/promapi/oas_handlers_gen.go | 169 ++++++++++++------ internal/promapi/oas_response_encoders_gen.go | 19 ++ internal/promapi/oas_schemas_gen.go | 53 ++++++ internal/pyroscopeapi/oas_client_gen.go | 11 ++ internal/pyroscopeapi/oas_handlers_gen.go | 65 ++++--- .../pyroscopeapi/oas_response_encoders_gen.go | 10 ++ internal/pyroscopeapi/oas_schemas_gen.go | 34 ++++ internal/sentryapi/oas_client_gen.go | 5 + internal/sentryapi/oas_handlers_gen.go | 26 ++- .../sentryapi/oas_response_encoders_gen.go | 7 + internal/tempoapi/oas_client_gen.go | 13 ++ internal/tempoapi/oas_handlers_gen.go | 78 +++++--- .../tempoapi/oas_response_encoders_gen.go | 12 ++ .../yqlclient/ytqueryapi/oas_client_gen.go | 9 + .../yqlclient/ytqueryapi/oas_handlers_gen.go | 92 ++++++---- .../ytqueryapi/oas_response_encoders_gen.go | 10 ++ .../yqlclient/ytqueryapi/oas_schemas_gen.go | 38 ++++ 22 files changed, 628 insertions(+), 160 deletions(-) diff --git a/internal/lokiapi/oas_client_gen.go b/internal/lokiapi/oas_client_gen.go index 918511d7..9cdac101 100644 --- a/internal/lokiapi/oas_client_gen.go +++ b/internal/lokiapi/oas_client_gen.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" + semconv "go.opentelemetry.io/otel/semconv/v1.19.0" "go.opentelemetry.io/otel/trace" "github.com/ogen-go/ogen/conv" @@ -86,6 +87,8 @@ func (c *Client) LabelValues(ctx context.Context, params LabelValuesParams) (*Va func (c *Client) sendLabelValues(ctx context.Context, params LabelValuesParams) (res *Values, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("labelValues"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/loki/api/v1/label/{name}/values"), } // Run stopwatch. @@ -275,6 +278,8 @@ func (c *Client) Labels(ctx context.Context, params LabelsParams) (*Labels, erro func (c *Client) sendLabels(ctx context.Context, params LabelsParams) (res *Labels, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("labels"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/loki/api/v1/labels"), } // Run stopwatch. @@ -427,6 +432,8 @@ func (c *Client) Push(ctx context.Context, request PushReq) error { func (c *Client) sendPush(ctx context.Context, request PushReq) (res *PushNoContent, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("push"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/loki/api/v1/push"), } // Validate request before sending. switch request := request.(type) { @@ -517,6 +524,8 @@ func (c *Client) Query(ctx context.Context, params QueryParams) (*QueryResponse, func (c *Client) sendQuery(ctx context.Context, params QueryParams) (res *QueryResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("query"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/loki/api/v1/query"), } // Run stopwatch. @@ -677,6 +686,8 @@ func (c *Client) QueryRange(ctx context.Context, params QueryRangeParams) (*Quer func (c *Client) sendQueryRange(ctx context.Context, params QueryRangeParams) (res *QueryResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("queryRange"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/loki/api/v1/query_range"), } // Run stopwatch. @@ -897,6 +908,8 @@ func (c *Client) Series(ctx context.Context, params SeriesParams) (*Maps, error) func (c *Client) sendSeries(ctx context.Context, params SeriesParams) (res *Maps, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("series"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/loki/api/v1/series"), } // Run stopwatch. diff --git a/internal/lokiapi/oas_handlers_gen.go b/internal/lokiapi/oas_handlers_gen.go index 05f82661..99fb79a6 100644 --- a/internal/lokiapi/oas_handlers_gen.go +++ b/internal/lokiapi/oas_handlers_gen.go @@ -131,22 +131,27 @@ func (s *Server) handleLabelValuesRequest(args [1]string, argsEscaped bool, w ht response, err = s.h.LabelValues(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeLabelValuesResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -255,22 +260,27 @@ func (s *Server) handleLabelsRequest(args [0]string, argsEscaped bool, w http.Re response, err = s.h.Labels(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeLabelsResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -366,22 +376,27 @@ func (s *Server) handlePushRequest(args [0]string, argsEscaped bool, w http.Resp err = s.h.Push(ctx, request) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodePushResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -493,22 +508,27 @@ func (s *Server) handleQueryRequest(args [0]string, argsEscaped bool, w http.Res response, err = s.h.Query(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeQueryResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -632,22 +652,27 @@ func (s *Server) handleQueryRangeRequest(args [0]string, argsEscaped bool, w htt response, err = s.h.QueryRange(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeQueryRangeResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -755,22 +780,27 @@ func (s *Server) handleSeriesRequest(args [0]string, argsEscaped bool, w http.Re response, err = s.h.Series(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeSeriesResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } diff --git a/internal/lokiapi/oas_response_encoders_gen.go b/internal/lokiapi/oas_response_encoders_gen.go index 4a54910d..1d1d2553 100644 --- a/internal/lokiapi/oas_response_encoders_gen.go +++ b/internal/lokiapi/oas_response_encoders_gen.go @@ -9,6 +9,8 @@ import ( "github.com/go-faster/jx" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" + + ht "github.com/ogen-go/ogen/http" ) func encodeLabelValuesResponse(response *Values, w http.ResponseWriter, span trace.Span) error { @@ -21,6 +23,7 @@ func encodeLabelValuesResponse(response *Values, w http.ResponseWriter, span tra if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -34,6 +37,7 @@ func encodeLabelsResponse(response *Labels, w http.ResponseWriter, span trace.Sp if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -54,6 +58,7 @@ func encodeQueryResponse(response *QueryResponse, w http.ResponseWriter, span tr if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -67,6 +72,7 @@ func encodeQueryRangeResponse(response *QueryResponse, w http.ResponseWriter, sp if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -80,6 +86,7 @@ func encodeSeriesResponse(response *Maps, w http.ResponseWriter, span trace.Span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -103,6 +110,10 @@ func encodeErrorResponse(response *ErrorStatusCode, w http.ResponseWriter, span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + + if code >= http.StatusInternalServerError { + return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code)) + } return nil } diff --git a/internal/lokiapi/oas_schemas_gen.go b/internal/lokiapi/oas_schemas_gen.go index 70132865..0d8f5414 100644 --- a/internal/lokiapi/oas_schemas_gen.go +++ b/internal/lokiapi/oas_schemas_gen.go @@ -21,6 +21,14 @@ const ( DirectionForward Direction = "forward" ) +// AllValues returns all Direction values. +func (Direction) AllValues() []Direction { + return []Direction{ + DirectionBackward, + DirectionForward, + } +} + // MarshalText implements encoding.TextMarshaler. func (s Direction) MarshalText() ([]byte, error) { switch s { diff --git a/internal/promapi/oas_client_gen.go b/internal/promapi/oas_client_gen.go index 9a7bd030..b0c99499 100644 --- a/internal/promapi/oas_client_gen.go +++ b/internal/promapi/oas_client_gen.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" + semconv "go.opentelemetry.io/otel/semconv/v1.19.0" "go.opentelemetry.io/otel/trace" "github.com/ogen-go/ogen/conv" @@ -84,6 +85,8 @@ func (c *Client) GetLabelValues(ctx context.Context, params GetLabelValuesParams func (c *Client) sendGetLabelValues(ctx context.Context, params GetLabelValuesParams) (res *LabelValuesResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getLabelValues"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/v1/label/{label}/values"), } // Run stopwatch. @@ -239,6 +242,8 @@ func (c *Client) GetLabels(ctx context.Context, params GetLabelsParams) (*Labels func (c *Client) sendGetLabels(ctx context.Context, params GetLabelsParams) (res *LabelsResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getLabels"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/v1/labels"), } // Run stopwatch. @@ -375,6 +380,8 @@ func (c *Client) GetMetadata(ctx context.Context, params GetMetadataParams) (*Me func (c *Client) sendGetMetadata(ctx context.Context, params GetMetadataParams) (res *MetadataResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getMetadata"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/v1/metadata"), } // Run stopwatch. @@ -501,6 +508,8 @@ func (c *Client) GetQuery(ctx context.Context, params GetQueryParams) (*QueryRes func (c *Client) sendGetQuery(ctx context.Context, params GetQueryParams) (res *QueryResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getQuery"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/v1/query"), } // Run stopwatch. @@ -610,6 +619,8 @@ func (c *Client) GetQueryExemplars(ctx context.Context, params GetQueryExemplars func (c *Client) sendGetQueryExemplars(ctx context.Context, params GetQueryExemplarsParams) (res *QueryExemplarsResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getQueryExemplars"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/v1/query_exemplars"), } // Run stopwatch. @@ -733,6 +744,8 @@ func (c *Client) GetQueryRange(ctx context.Context, params GetQueryRangeParams) func (c *Client) sendGetQueryRange(ctx context.Context, params GetQueryRangeParams) (res *QueryResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getQueryRange"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/v1/query_range"), } // Run stopwatch. @@ -888,6 +901,8 @@ func (c *Client) GetRules(ctx context.Context, params GetRulesParams) (*RulesRes func (c *Client) sendGetRules(ctx context.Context, params GetRulesParams) (res *RulesResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getRules"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/v1/rules"), } // Run stopwatch. @@ -1049,6 +1064,8 @@ func (c *Client) GetSeries(ctx context.Context, params GetSeriesParams) (*Series func (c *Client) sendGetSeries(ctx context.Context, params GetSeriesParams) (res *SeriesResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getSeries"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/v1/series"), } // Run stopwatch. @@ -1179,6 +1196,8 @@ func (c *Client) PostLabels(ctx context.Context) (*LabelsResponse, error) { func (c *Client) sendPostLabels(ctx context.Context) (res *LabelsResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("postLabels"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/api/v1/labels"), } // Run stopwatch. @@ -1250,6 +1269,8 @@ func (c *Client) PostQuery(ctx context.Context, request *QueryForm) (*QueryRespo func (c *Client) sendPostQuery(ctx context.Context, request *QueryForm) (res *QueryResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("postQuery"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/api/v1/query"), } // Run stopwatch. @@ -1324,6 +1345,8 @@ func (c *Client) PostQueryExemplars(ctx context.Context) (*QueryExemplarsRespons func (c *Client) sendPostQueryExemplars(ctx context.Context) (res *QueryExemplarsResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("postQueryExemplars"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/api/v1/query_exemplars"), } // Run stopwatch. @@ -1395,6 +1418,8 @@ func (c *Client) PostQueryRange(ctx context.Context, request *QueryRangeForm) (* func (c *Client) sendPostQueryRange(ctx context.Context, request *QueryRangeForm) (res *QueryResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("postQueryRange"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/api/v1/query_range"), } // Run stopwatch. @@ -1469,6 +1494,8 @@ func (c *Client) PostSeries(ctx context.Context) (*SeriesResponse, error) { func (c *Client) sendPostSeries(ctx context.Context) (res *SeriesResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("postSeries"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/api/v1/series"), } // Run stopwatch. diff --git a/internal/promapi/oas_handlers_gen.go b/internal/promapi/oas_handlers_gen.go index a69df549..a8c52adc 100644 --- a/internal/promapi/oas_handlers_gen.go +++ b/internal/promapi/oas_handlers_gen.go @@ -121,22 +121,27 @@ func (s *Server) handleGetLabelValuesRequest(args [1]string, argsEscaped bool, w response, err = s.h.GetLabelValues(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetLabelValuesResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -238,22 +243,27 @@ func (s *Server) handleGetLabelsRequest(args [0]string, argsEscaped bool, w http response, err = s.h.GetLabels(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetLabelsResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -355,22 +365,27 @@ func (s *Server) handleGetMetadataRequest(args [0]string, argsEscaped bool, w ht response, err = s.h.GetMetadata(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetMetadataResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -470,22 +485,27 @@ func (s *Server) handleGetQueryRequest(args [0]string, argsEscaped bool, w http. response, err = s.h.GetQuery(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetQueryResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -589,22 +609,27 @@ func (s *Server) handleGetQueryExemplarsRequest(args [0]string, argsEscaped bool response, err = s.h.GetQueryExemplars(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetQueryExemplarsResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -716,22 +741,27 @@ func (s *Server) handleGetQueryRangeRequest(args [0]string, argsEscaped bool, w response, err = s.h.GetQueryRange(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetQueryRangeResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -837,22 +867,27 @@ func (s *Server) handleGetRulesRequest(args [0]string, argsEscaped bool, w http. response, err = s.h.GetRules(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetRulesResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -956,22 +991,27 @@ func (s *Server) handleGetSeriesRequest(args [0]string, argsEscaped bool, w http response, err = s.h.GetSeries(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetSeriesResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -1046,22 +1086,27 @@ func (s *Server) handlePostLabelsRequest(args [0]string, argsEscaped bool, w htt response, err = s.h.PostLabels(ctx) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodePostLabelsResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -1157,22 +1202,27 @@ func (s *Server) handlePostQueryRequest(args [0]string, argsEscaped bool, w http response, err = s.h.PostQuery(ctx, request) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodePostQueryResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -1249,22 +1299,27 @@ func (s *Server) handlePostQueryExemplarsRequest(args [0]string, argsEscaped boo response, err = s.h.PostQueryExemplars(ctx) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodePostQueryExemplarsResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -1360,22 +1415,27 @@ func (s *Server) handlePostQueryRangeRequest(args [0]string, argsEscaped bool, w response, err = s.h.PostQueryRange(ctx, request) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodePostQueryRangeResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -1452,22 +1512,27 @@ func (s *Server) handlePostSeriesRequest(args [0]string, argsEscaped bool, w htt response, err = s.h.PostSeries(ctx) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*FailStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodePostSeriesResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } diff --git a/internal/promapi/oas_response_encoders_gen.go b/internal/promapi/oas_response_encoders_gen.go index b4a4dd28..0dcbcf58 100644 --- a/internal/promapi/oas_response_encoders_gen.go +++ b/internal/promapi/oas_response_encoders_gen.go @@ -9,6 +9,8 @@ import ( "github.com/go-faster/jx" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" + + ht "github.com/ogen-go/ogen/http" ) func encodeGetLabelValuesResponse(response *LabelValuesResponse, w http.ResponseWriter, span trace.Span) error { @@ -21,6 +23,7 @@ func encodeGetLabelValuesResponse(response *LabelValuesResponse, w http.Response if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -34,6 +37,7 @@ func encodeGetLabelsResponse(response *LabelsResponse, w http.ResponseWriter, sp if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -47,6 +51,7 @@ func encodeGetMetadataResponse(response *MetadataResponse, w http.ResponseWriter if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -60,6 +65,7 @@ func encodeGetQueryResponse(response *QueryResponse, w http.ResponseWriter, span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -73,6 +79,7 @@ func encodeGetQueryExemplarsResponse(response *QueryExemplarsResponse, w http.Re if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -86,6 +93,7 @@ func encodeGetQueryRangeResponse(response *QueryResponse, w http.ResponseWriter, if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -99,6 +107,7 @@ func encodeGetRulesResponse(response *RulesResponse, w http.ResponseWriter, span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -112,6 +121,7 @@ func encodeGetSeriesResponse(response *SeriesResponse, w http.ResponseWriter, sp if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -125,6 +135,7 @@ func encodePostLabelsResponse(response *LabelsResponse, w http.ResponseWriter, s if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -138,6 +149,7 @@ func encodePostQueryResponse(response *QueryResponse, w http.ResponseWriter, spa if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -151,6 +163,7 @@ func encodePostQueryExemplarsResponse(response *QueryExemplarsResponse, w http.R if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -164,6 +177,7 @@ func encodePostQueryRangeResponse(response *QueryResponse, w http.ResponseWriter if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -177,6 +191,7 @@ func encodePostSeriesResponse(response *SeriesResponse, w http.ResponseWriter, s if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -200,6 +215,10 @@ func encodeErrorResponse(response *FailStatusCode, w http.ResponseWriter, span t if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + + if code >= http.StatusInternalServerError { + return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code)) + } return nil } diff --git a/internal/promapi/oas_schemas_gen.go b/internal/promapi/oas_schemas_gen.go index 4c7e1eaa..7436d525 100644 --- a/internal/promapi/oas_schemas_gen.go +++ b/internal/promapi/oas_schemas_gen.go @@ -205,6 +205,15 @@ const ( AlertingRuleStateInactive AlertingRuleState = "inactive" ) +// AllValues returns all AlertingRuleState values. +func (AlertingRuleState) AllValues() []AlertingRuleState { + return []AlertingRuleState{ + AlertingRuleStatePending, + AlertingRuleStateFiring, + AlertingRuleStateInactive, + } +} + // MarshalText implements encoding.TextMarshaler. func (s AlertingRuleState) MarshalText() ([]byte, error) { switch s { @@ -479,6 +488,19 @@ const ( FailErrorTypeNotFound FailErrorType = "not_found" ) +// AllValues returns all FailErrorType values. +func (FailErrorType) AllValues() []FailErrorType { + return []FailErrorType{ + FailErrorTypeTimeout, + FailErrorTypeCanceled, + FailErrorTypeExecution, + FailErrorTypeBadData, + FailErrorTypeInternal, + FailErrorTypeUnavailable, + FailErrorTypeNotFound, + } +} + // MarshalText implements encoding.TextMarshaler. func (s FailErrorType) MarshalText() ([]byte, error) { switch s { @@ -563,6 +585,14 @@ const ( GetRulesTypeRecord GetRulesType = "record" ) +// AllValues returns all GetRulesType values. +func (GetRulesType) AllValues() []GetRulesType { + return []GetRulesType{ + GetRulesTypeAlert, + GetRulesTypeRecord, + } +} + // MarshalText implements encoding.TextMarshaler. func (s GetRulesType) MarshalText() ([]byte, error) { switch s { @@ -835,6 +865,20 @@ const ( MetricMetadataTypeUnknown MetricMetadataType = "unknown" ) +// AllValues returns all MetricMetadataType values. +func (MetricMetadataType) AllValues() []MetricMetadataType { + return []MetricMetadataType{ + MetricMetadataTypeCounter, + MetricMetadataTypeGauge, + MetricMetadataTypeHistogram, + MetricMetadataTypeGaugehistogram, + MetricMetadataTypeSummary, + MetricMetadataTypeInfo, + MetricMetadataTypeStateset, + MetricMetadataTypeUnknown, + } +} + // MarshalText implements encoding.TextMarshaler. func (s MetricMetadataType) MarshalText() ([]byte, error) { switch s { @@ -1862,6 +1906,15 @@ const ( RuleHealthErr RuleHealth = "err" ) +// AllValues returns all RuleHealth values. +func (RuleHealth) AllValues() []RuleHealth { + return []RuleHealth{ + RuleHealthUnknown, + RuleHealthOk, + RuleHealthErr, + } +} + // MarshalText implements encoding.TextMarshaler. func (s RuleHealth) MarshalText() ([]byte, error) { switch s { diff --git a/internal/pyroscopeapi/oas_client_gen.go b/internal/pyroscopeapi/oas_client_gen.go index 17ed0398..4e2775f2 100644 --- a/internal/pyroscopeapi/oas_client_gen.go +++ b/internal/pyroscopeapi/oas_client_gen.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" + semconv "go.opentelemetry.io/otel/semconv/v1.19.0" "go.opentelemetry.io/otel/trace" "github.com/ogen-go/ogen/conv" @@ -87,6 +88,8 @@ func (c *Client) GetApps(ctx context.Context) ([]ApplicationMetadata, error) { func (c *Client) sendGetApps(ctx context.Context) (res []ApplicationMetadata, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getApps"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/apps"), } // Run stopwatch. @@ -158,6 +161,8 @@ func (c *Client) Ingest(ctx context.Context, request *IngestReqWithContentType, func (c *Client) sendIngest(ctx context.Context, request *IngestReqWithContentType, params IngestParams) (res *IngestOK, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("ingest"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/ingest"), } // Run stopwatch. @@ -378,6 +383,8 @@ func (c *Client) LabelValues(ctx context.Context, params LabelValuesParams) (Lab func (c *Client) sendLabelValues(ctx context.Context, params LabelValuesParams) (res LabelValues, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("labelValues"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/label-values"), } // Run stopwatch. @@ -524,6 +531,8 @@ func (c *Client) Labels(ctx context.Context, params LabelsParams) (Labels, error func (c *Client) sendLabels(ctx context.Context, params LabelsParams) (res Labels, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("labels"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/labels"), } // Run stopwatch. @@ -657,6 +666,8 @@ func (c *Client) Render(ctx context.Context, params RenderParams) (*FlamebearerP func (c *Client) sendRender(ctx context.Context, params RenderParams) (res *FlamebearerProfileV1, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("render"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/render"), } // Run stopwatch. diff --git a/internal/pyroscopeapi/oas_handlers_gen.go b/internal/pyroscopeapi/oas_handlers_gen.go index cd6c8f43..398bf309 100644 --- a/internal/pyroscopeapi/oas_handlers_gen.go +++ b/internal/pyroscopeapi/oas_handlers_gen.go @@ -93,22 +93,27 @@ func (s *Server) handleGetAppsRequest(args [0]string, argsEscaped bool, w http.R response, err = s.h.GetApps(ctx) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetAppsResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -247,22 +252,27 @@ func (s *Server) handleIngestRequest(args [0]string, argsEscaped bool, w http.Re err = s.h.Ingest(ctx, request, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeIngestResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -370,22 +380,27 @@ func (s *Server) handleLabelValuesRequest(args [0]string, argsEscaped bool, w ht response, err = s.h.LabelValues(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeLabelValuesResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -489,22 +504,27 @@ func (s *Server) handleLabelsRequest(args [0]string, argsEscaped bool, w http.Re response, err = s.h.Labels(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeLabelsResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -625,22 +645,27 @@ func (s *Server) handleRenderRequest(args [0]string, argsEscaped bool, w http.Re response, err = s.h.Render(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeRenderResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } diff --git a/internal/pyroscopeapi/oas_response_encoders_gen.go b/internal/pyroscopeapi/oas_response_encoders_gen.go index 5d14276b..340da318 100644 --- a/internal/pyroscopeapi/oas_response_encoders_gen.go +++ b/internal/pyroscopeapi/oas_response_encoders_gen.go @@ -9,6 +9,8 @@ import ( "github.com/go-faster/jx" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" + + ht "github.com/ogen-go/ogen/http" ) func encodeGetAppsResponse(response []ApplicationMetadata, w http.ResponseWriter, span trace.Span) error { @@ -25,6 +27,7 @@ func encodeGetAppsResponse(response []ApplicationMetadata, w http.ResponseWriter if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -45,6 +48,7 @@ func encodeLabelValuesResponse(response LabelValues, w http.ResponseWriter, span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -58,6 +62,7 @@ func encodeLabelsResponse(response Labels, w http.ResponseWriter, span trace.Spa if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -71,6 +76,7 @@ func encodeRenderResponse(response *FlamebearerProfileV1, w http.ResponseWriter, if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -94,6 +100,10 @@ func encodeErrorResponse(response *ErrorStatusCode, w http.ResponseWriter, span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + + if code >= http.StatusInternalServerError { + return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code)) + } return nil } diff --git a/internal/pyroscopeapi/oas_schemas_gen.go b/internal/pyroscopeapi/oas_schemas_gen.go index 895f09bf..a7b47263 100644 --- a/internal/pyroscopeapi/oas_schemas_gen.go +++ b/internal/pyroscopeapi/oas_schemas_gen.go @@ -72,6 +72,18 @@ const ( ApplicationMetadataUnitsLockSamples ApplicationMetadataUnits = "lock_samples" ) +// AllValues returns all ApplicationMetadataUnits values. +func (ApplicationMetadataUnits) AllValues() []ApplicationMetadataUnits { + return []ApplicationMetadataUnits{ + ApplicationMetadataUnitsSamples, + ApplicationMetadataUnitsObjects, + ApplicationMetadataUnitsGoroutines, + ApplicationMetadataUnitsBytes, + ApplicationMetadataUnitsLockNanoseconds, + ApplicationMetadataUnitsLockSamples, + } +} + // MarshalText implements encoding.TextMarshaler. func (s ApplicationMetadataUnits) MarshalText() ([]byte, error) { switch s { @@ -218,6 +230,18 @@ const ( FlamebearerMetadataV1UnitsLockSamples FlamebearerMetadataV1Units = "lock_samples" ) +// AllValues returns all FlamebearerMetadataV1Units values. +func (FlamebearerMetadataV1Units) AllValues() []FlamebearerMetadataV1Units { + return []FlamebearerMetadataV1Units{ + FlamebearerMetadataV1UnitsSamples, + FlamebearerMetadataV1UnitsObjects, + FlamebearerMetadataV1UnitsGoroutines, + FlamebearerMetadataV1UnitsBytes, + FlamebearerMetadataV1UnitsLockNanoseconds, + FlamebearerMetadataV1UnitsLockSamples, + } +} + // MarshalText implements encoding.TextMarshaler. func (s FlamebearerMetadataV1Units) MarshalText() ([]byte, error) { switch s { @@ -1270,6 +1294,16 @@ const ( RenderFormatHTML RenderFormat = "html" ) +// AllValues returns all RenderFormat values. +func (RenderFormat) AllValues() []RenderFormat { + return []RenderFormat{ + RenderFormatJSON, + RenderFormatPprof, + RenderFormatCollapsed, + RenderFormatHTML, + } +} + // MarshalText implements encoding.TextMarshaler. func (s RenderFormat) MarshalText() ([]byte, error) { switch s { diff --git a/internal/sentryapi/oas_client_gen.go b/internal/sentryapi/oas_client_gen.go index fa4f0290..b45d25c1 100644 --- a/internal/sentryapi/oas_client_gen.go +++ b/internal/sentryapi/oas_client_gen.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" + semconv "go.opentelemetry.io/otel/semconv/v1.19.0" "go.opentelemetry.io/otel/trace" ht "github.com/ogen-go/ogen/http" @@ -85,6 +86,8 @@ func (c *Client) Dummy(ctx context.Context) (*Event, error) { func (c *Client) sendDummy(ctx context.Context) (res *Event, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("dummy"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/dummy"), } // Run stopwatch. @@ -156,6 +159,8 @@ func (c *Client) Envelope(ctx context.Context, request *EnvelopeReqWithContentTy func (c *Client) sendEnvelope(ctx context.Context, request *EnvelopeReqWithContentType) (res *EnvelopeOK, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("envelope"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/envelope"), } // Run stopwatch. diff --git a/internal/sentryapi/oas_handlers_gen.go b/internal/sentryapi/oas_handlers_gen.go index 9a02aae7..bdf6571a 100644 --- a/internal/sentryapi/oas_handlers_gen.go +++ b/internal/sentryapi/oas_handlers_gen.go @@ -92,22 +92,27 @@ func (s *Server) handleDummyRequest(args [0]string, argsEscaped bool, w http.Res response, err = s.h.Dummy(ctx) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeDummyResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -203,22 +208,27 @@ func (s *Server) handleEnvelopeRequest(args [0]string, argsEscaped bool, w http. err = s.h.Envelope(ctx, request) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeEnvelopeResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } diff --git a/internal/sentryapi/oas_response_encoders_gen.go b/internal/sentryapi/oas_response_encoders_gen.go index 545b7f26..b6b687fb 100644 --- a/internal/sentryapi/oas_response_encoders_gen.go +++ b/internal/sentryapi/oas_response_encoders_gen.go @@ -9,6 +9,8 @@ import ( "github.com/go-faster/jx" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" + + ht "github.com/ogen-go/ogen/http" ) func encodeDummyResponse(response *Event, w http.ResponseWriter, span trace.Span) error { @@ -21,6 +23,7 @@ func encodeDummyResponse(response *Event, w http.ResponseWriter, span trace.Span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -51,6 +54,10 @@ func encodeErrorResponse(response *ErrorStatusCode, w http.ResponseWriter, span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + + if code >= http.StatusInternalServerError { + return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code)) + } return nil } diff --git a/internal/tempoapi/oas_client_gen.go b/internal/tempoapi/oas_client_gen.go index 64f77c76..ea4b8f5c 100644 --- a/internal/tempoapi/oas_client_gen.go +++ b/internal/tempoapi/oas_client_gen.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" + semconv "go.opentelemetry.io/otel/semconv/v1.19.0" "go.opentelemetry.io/otel/trace" "github.com/ogen-go/ogen/conv" @@ -86,6 +87,8 @@ func (c *Client) Echo(ctx context.Context) (EchoOK, error) { func (c *Client) sendEcho(ctx context.Context) (res EchoOK, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("echo"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/echo"), } // Run stopwatch. @@ -157,6 +160,8 @@ func (c *Client) Search(ctx context.Context, params SearchParams) (*Traces, erro func (c *Client) sendSearch(ctx context.Context, params SearchParams) (res *Traces, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("search"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/search"), } // Run stopwatch. @@ -351,6 +356,8 @@ func (c *Client) SearchTagValues(ctx context.Context, params SearchTagValuesPara func (c *Client) sendSearchTagValues(ctx context.Context, params SearchTagValuesParams) (res *TagValues, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("searchTagValues"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/search/tag/{tag_name}/values"), } // Run stopwatch. @@ -442,6 +449,8 @@ func (c *Client) SearchTagValuesV2(ctx context.Context, params SearchTagValuesV2 func (c *Client) sendSearchTagValuesV2(ctx context.Context, params SearchTagValuesV2Params) (res *TagValuesV2, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("searchTagValuesV2"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/v2/search/tag/{tag_name}/values"), } // Run stopwatch. @@ -532,6 +541,8 @@ func (c *Client) SearchTags(ctx context.Context) (*TagNames, error) { func (c *Client) sendSearchTags(ctx context.Context) (res *TagNames, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("searchTags"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/search/tags"), } // Run stopwatch. @@ -603,6 +614,8 @@ func (c *Client) TraceByID(ctx context.Context, params TraceByIDParams) (TraceBy func (c *Client) sendTraceByID(ctx context.Context, params TraceByIDParams) (res TraceByIDRes, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("traceByID"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/api/traces/{traceID}"), } // Run stopwatch. diff --git a/internal/tempoapi/oas_handlers_gen.go b/internal/tempoapi/oas_handlers_gen.go index b115e22d..804eba47 100644 --- a/internal/tempoapi/oas_handlers_gen.go +++ b/internal/tempoapi/oas_handlers_gen.go @@ -92,22 +92,27 @@ func (s *Server) handleEchoRequest(args [0]string, argsEscaped bool, w http.Resp response, err = s.h.Echo(ctx) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeEchoResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -227,22 +232,27 @@ func (s *Server) handleSearchRequest(args [0]string, argsEscaped bool, w http.Re response, err = s.h.Search(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeSearchResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -338,22 +348,27 @@ func (s *Server) handleSearchTagValuesRequest(args [1]string, argsEscaped bool, response, err = s.h.SearchTagValues(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeSearchTagValuesResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -450,22 +465,27 @@ func (s *Server) handleSearchTagValuesV2Request(args [1]string, argsEscaped bool response, err = s.h.SearchTagValuesV2(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeSearchTagValuesV2Response(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -542,22 +562,27 @@ func (s *Server) handleSearchTagsRequest(args [0]string, argsEscaped bool, w htt response, err = s.h.SearchTags(ctx) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeSearchTagsResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -661,22 +686,27 @@ func (s *Server) handleTraceByIDRequest(args [1]string, argsEscaped bool, w http response, err = s.h.TraceByID(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeTraceByIDResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } diff --git a/internal/tempoapi/oas_response_encoders_gen.go b/internal/tempoapi/oas_response_encoders_gen.go index 85539308..0b944fb4 100644 --- a/internal/tempoapi/oas_response_encoders_gen.go +++ b/internal/tempoapi/oas_response_encoders_gen.go @@ -10,6 +10,8 @@ import ( "github.com/go-faster/jx" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" + + ht "github.com/ogen-go/ogen/http" ) func encodeEchoResponse(response EchoOK, w http.ResponseWriter, span trace.Span) error { @@ -21,6 +23,7 @@ func encodeEchoResponse(response EchoOK, w http.ResponseWriter, span trace.Span) if _, err := io.Copy(writer, response); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -34,6 +37,7 @@ func encodeSearchResponse(response *Traces, w http.ResponseWriter, span trace.Sp if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -47,6 +51,7 @@ func encodeSearchTagValuesResponse(response *TagValues, w http.ResponseWriter, s if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -60,6 +65,7 @@ func encodeSearchTagValuesV2Response(response *TagValuesV2, w http.ResponseWrite if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -73,6 +79,7 @@ func encodeSearchTagsResponse(response *TagNames, w http.ResponseWriter, span tr if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -87,6 +94,7 @@ func encodeTraceByIDResponse(response TraceByIDRes, w http.ResponseWriter, span if _, err := io.Copy(writer, response); err != nil { return errors.Wrap(err, "write") } + return nil case *TraceByIDNotFound: @@ -120,6 +128,10 @@ func encodeErrorResponse(response *ErrorStatusCode, w http.ResponseWriter, span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + + if code >= http.StatusInternalServerError { + return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code)) + } return nil } diff --git a/internal/yqlclient/ytqueryapi/oas_client_gen.go b/internal/yqlclient/ytqueryapi/oas_client_gen.go index 3856db1f..6b3efcce 100644 --- a/internal/yqlclient/ytqueryapi/oas_client_gen.go +++ b/internal/yqlclient/ytqueryapi/oas_client_gen.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" + semconv "go.opentelemetry.io/otel/semconv/v1.19.0" "go.opentelemetry.io/otel/trace" "github.com/ogen-go/ogen/conv" @@ -89,6 +90,8 @@ func (c *Client) AbortQuery(ctx context.Context, params AbortQueryParams) error func (c *Client) sendAbortQuery(ctx context.Context, params AbortQueryParams) (res *AbortedQuery, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("abortQuery"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/api/v4/abort_query"), } // Run stopwatch. @@ -232,6 +235,8 @@ func (c *Client) GetQuery(ctx context.Context, params GetQueryParams) (*QuerySta func (c *Client) sendGetQuery(ctx context.Context, params GetQueryParams) (res *QueryStatus, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("getQuery"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/api/v4/get_query"), } // Run stopwatch. @@ -375,6 +380,8 @@ func (c *Client) ReadQueryResult(ctx context.Context, params ReadQueryResultPara func (c *Client) sendReadQueryResult(ctx context.Context, params ReadQueryResultParams) (res QueryResult, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("readQueryResult"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/api/v4/read_query_result"), } // Run stopwatch. @@ -549,6 +556,8 @@ func (c *Client) StartQuery(ctx context.Context, params StartQueryParams) (*Star func (c *Client) sendStartQuery(ctx context.Context, params StartQueryParams) (res *StartedQuery, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("startQuery"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/api/v4/start_query"), } // Run stopwatch. diff --git a/internal/yqlclient/ytqueryapi/oas_handlers_gen.go b/internal/yqlclient/ytqueryapi/oas_handlers_gen.go index abd96e9a..67831537 100644 --- a/internal/yqlclient/ytqueryapi/oas_handlers_gen.go +++ b/internal/yqlclient/ytqueryapi/oas_handlers_gen.go @@ -73,8 +73,9 @@ func (s *Server) handleAbortQueryRequest(args [0]string, argsEscaped bool, w htt Security: "YTToken", Err: err, } - recordError("Security:YTToken", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + recordError("Security:YTToken", err) + } return } if ok { @@ -102,8 +103,9 @@ func (s *Server) handleAbortQueryRequest(args [0]string, argsEscaped bool, w htt OperationContext: opErrContext, Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, } - recordError("Security", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + recordError("Security", err) + } return } } @@ -160,22 +162,27 @@ func (s *Server) handleAbortQueryRequest(args [0]string, argsEscaped bool, w htt err = s.h.AbortQuery(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeAbortQueryResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -233,8 +240,9 @@ func (s *Server) handleGetQueryRequest(args [0]string, argsEscaped bool, w http. Security: "YTToken", Err: err, } - recordError("Security:YTToken", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + recordError("Security:YTToken", err) + } return } if ok { @@ -262,8 +270,9 @@ func (s *Server) handleGetQueryRequest(args [0]string, argsEscaped bool, w http. OperationContext: opErrContext, Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, } - recordError("Security", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + recordError("Security", err) + } return } } @@ -320,22 +329,27 @@ func (s *Server) handleGetQueryRequest(args [0]string, argsEscaped bool, w http. response, err = s.h.GetQuery(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeGetQueryResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -393,8 +407,9 @@ func (s *Server) handleReadQueryResultRequest(args [0]string, argsEscaped bool, Security: "YTToken", Err: err, } - recordError("Security:YTToken", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + recordError("Security:YTToken", err) + } return } if ok { @@ -422,8 +437,9 @@ func (s *Server) handleReadQueryResultRequest(args [0]string, argsEscaped bool, OperationContext: opErrContext, Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, } - recordError("Security", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + recordError("Security", err) + } return } } @@ -488,22 +504,27 @@ func (s *Server) handleReadQueryResultRequest(args [0]string, argsEscaped bool, response, err = s.h.ReadQueryResult(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeReadQueryResultResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } @@ -561,8 +582,9 @@ func (s *Server) handleStartQueryRequest(args [0]string, argsEscaped bool, w htt Security: "YTToken", Err: err, } - recordError("Security:YTToken", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + recordError("Security:YTToken", err) + } return } if ok { @@ -590,8 +612,9 @@ func (s *Server) handleStartQueryRequest(args [0]string, argsEscaped bool, w htt OperationContext: opErrContext, Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, } - recordError("Security", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + recordError("Security", err) + } return } } @@ -652,22 +675,27 @@ func (s *Server) handleStartQueryRequest(args [0]string, argsEscaped bool, w htt response, err = s.h.StartQuery(ctx, params) } if err != nil { - recordError("Internal", err) if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - encodeErrorResponse(errRes, w, span) + if err := encodeErrorResponse(errRes, w, span); err != nil { + recordError("Internal", err) + } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } - encodeErrorResponse(s.h.NewError(ctx, err), w, span) + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + recordError("Internal", err) + } return } if err := encodeStartQueryResponse(response, w, span); err != nil { recordError("EncodeResponse", err) - s.cfg.ErrorHandler(ctx, w, r, err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } return } } diff --git a/internal/yqlclient/ytqueryapi/oas_response_encoders_gen.go b/internal/yqlclient/ytqueryapi/oas_response_encoders_gen.go index 184fe729..16e0f0d3 100644 --- a/internal/yqlclient/ytqueryapi/oas_response_encoders_gen.go +++ b/internal/yqlclient/ytqueryapi/oas_response_encoders_gen.go @@ -10,6 +10,8 @@ import ( "github.com/go-faster/jx" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" + + ht "github.com/ogen-go/ogen/http" ) func encodeAbortQueryResponse(response *AbortedQuery, w http.ResponseWriter, span trace.Span) error { @@ -22,6 +24,7 @@ func encodeAbortQueryResponse(response *AbortedQuery, w http.ResponseWriter, spa if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -35,6 +38,7 @@ func encodeGetQueryResponse(response *QueryStatus, w http.ResponseWriter, span t if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -46,6 +50,7 @@ func encodeReadQueryResultResponse(response QueryResult, w http.ResponseWriter, if _, err := io.Copy(writer, response); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -59,6 +64,7 @@ func encodeStartQueryResponse(response *StartedQuery, w http.ResponseWriter, spa if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + return nil } @@ -82,6 +88,10 @@ func encodeErrorResponse(response *ErrorStatusCode, w http.ResponseWriter, span if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } + + if code >= http.StatusInternalServerError { + return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code)) + } return nil } diff --git a/internal/yqlclient/ytqueryapi/oas_schemas_gen.go b/internal/yqlclient/ytqueryapi/oas_schemas_gen.go index b50af410..d1edb8f9 100644 --- a/internal/yqlclient/ytqueryapi/oas_schemas_gen.go +++ b/internal/yqlclient/ytqueryapi/oas_schemas_gen.go @@ -196,6 +196,15 @@ const ( EngineChyt Engine = "chyt" ) +// AllValues returns all Engine values. +func (Engine) AllValues() []Engine { + return []Engine{ + EngineYql, + EngineQl, + EngineChyt, + } +} + // MarshalText implements encoding.TextMarshaler. func (s Engine) MarshalText() ([]byte, error) { switch s { @@ -319,6 +328,24 @@ const ( OperationStateFailing OperationState = "failing" ) +// AllValues returns all OperationState values. +func (OperationState) AllValues() []OperationState { + return []OperationState{ + OperationStateRunning, + OperationStatePending, + OperationStateCompleted, + OperationStateFailed, + OperationStateAborted, + OperationStateReviving, + OperationStateInitializing, + OperationStatePreparing, + OperationStateMaterializing, + OperationStateCompleting, + OperationStateAborting, + OperationStateFailing, + } +} + // MarshalText implements encoding.TextMarshaler. func (s OperationState) MarshalText() ([]byte, error) { switch s { @@ -820,6 +847,17 @@ const ( OutputFormatProtobuf OutputFormat = "protobuf" ) +// AllValues returns all OutputFormat values. +func (OutputFormat) AllValues() []OutputFormat { + return []OutputFormat{ + OutputFormatJSON, + OutputFormatYson, + OutputFormatDsv, + OutputFormatSchemafulDsv, + OutputFormatProtobuf, + } +} + // MarshalText implements encoding.TextMarshaler. func (s OutputFormat) MarshalText() ([]byte, error) { switch s {