Skip to content

Commit

Permalink
Seperate proto files and generate unified swagger docs
Browse files Browse the repository at this point in the history
Signed-off-by: Annanay <[email protected]>
  • Loading branch information
Annanay committed Mar 1, 2019
1 parent d22f364 commit 0ee8357
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 37 deletions.
22 changes: 0 additions & 22 deletions model/proto/api_v2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,6 @@ service CollectorService {
}
}

message GetTraceRequest {
bytes trace_id = 1 [
(gogoproto.nullable) = false,
(gogoproto.customtype) = "github.com/jaegertracing/jaeger/model.TraceID",
(gogoproto.customname) = "TraceID"
];
}

message GetTraceResponseStream {
repeated jaeger.api_v2.Span spans = 1 [
(gogoproto.nullable) = false
];
}

service QueryService {
rpc GetTrace(GetTraceRequest) returns (stream GetTraceResponseStream) {
option (google.api.http) = {
get: "/api/v2/traces/{trace_id}"
};
}
}

enum SamplingStrategyType {
PROBABILISTIC = 0;
RATE_LIMITING = 1;
Expand Down
70 changes: 70 additions & 0 deletions model/proto/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2018 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax="proto3";

package jaeger.api_v2;

import "model.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "protoc-gen-swagger/options/annotations.proto";

option go_package = "api_v2";
option java_package = "io.jaegertracing.api_v2";

// Enable gogoprotobuf extensions (https://github.com/gogo/protobuf/blob/master/extensions.md).
// Enable custom Marshal method.
option (gogoproto.marshaler_all) = true;
// Enable custom Unmarshal method.
option (gogoproto.unmarshaler_all) = true;
// Enable custom Size method (Required by Marshal and Unmarshal).
option (gogoproto.sizer_all) = true;
// Enable registration with golang/protobuf for the grpc-gateway.
option (gogoproto.goproto_registration) = true;

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
info: {
version: "1.0";
};
external_docs: {
url: "https://github.com/jaegertracing/jaeger";
description: "Jaeger API";
}
schemes: HTTP;
schemes: HTTPS;
};


message GetTraceRequest {
bytes trace_id = 1 [
(gogoproto.nullable) = false,
(gogoproto.customtype) = "github.com/jaegertracing/jaeger/model.TraceID",
(gogoproto.customname) = "TraceID"
];
}

message GetTraceResponseStream {
repeated jaeger.api_v2.Span spans = 1 [
(gogoproto.nullable) = false
];
}

service QueryService {
rpc GetTrace(GetTraceRequest) returns (stream GetTraceResponseStream) {
option (google.api.http) = {
get: "/api/v2/traces/{trace_id}"
};
}
}
72 changes: 57 additions & 15 deletions proto-gen/openapi/api_v2.swagger.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"swagger": "2.0",
"info": {
"title": "api_v2.proto",
"version": "version not set"
"title": "model/proto/api_v2.proto",
"version": "1.0"
},
"schemes": [
"http",
Expand All @@ -20,7 +20,7 @@
"operationId": "GetSamplingStrategy",
"responses": {
"200": {
"description": "",
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/api_v2SamplingStrategyResponse"
}
Expand All @@ -46,7 +46,7 @@
"operationId": "PostSpans",
"responses": {
"200": {
"description": "",
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/api_v2PostSpansResponse"
}
Expand All @@ -72,9 +72,9 @@
"operationId": "GetTrace",
"responses": {
"200": {
"description": "(streaming responses)",
"description": "A successful response.(streaming responses)",
"schema": {
"$ref": "#/definitions/api_v2GetTraceResponseStream"
"$ref": "#/x-stream-definitions/api_v2GetTraceResponseStream"
}
}
},
Expand Down Expand Up @@ -303,7 +303,7 @@
"format": "date-time"
},
"duration": {
"$ref": "#/definitions/protobufDuration"
"type": "string"
},
"tags": {
"type": "array",
Expand Down Expand Up @@ -366,21 +366,63 @@
],
"default": "STRING"
},
"protobufDuration": {
"protobufAny": {
"type": "object",
"properties": {
"seconds": {
"type_url": {
"type": "string",
"description": "A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. The last segment of the URL's path must represent\nthe fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading \".\" is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n URL, or have them precompiled into a binary to avoid any\n lookup. Therefore, binary compatibility needs to be preserved\n on changes to types. (Use versioned type names to manage\n breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics."
},
"value": {
"type": "string",
"format": "int64",
"title": "Signed seconds of the span of time. Must be from -315,576,000,000\nto +315,576,000,000 inclusive. Note: these bounds are computed from:\n60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years"
"format": "byte",
"description": "Must be a valid serialized protocol buffer of the above specified type."
}
},
"description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := ptypes.MarshalAny(foo)\n ...\n foo := \u0026pb.Foo{}\n if err := ptypes.UnmarshalAny(any, foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }"
},
"runtimeStreamError": {
"type": "object",
"properties": {
"grpc_code": {
"type": "integer",
"format": "int32"
},
"nanos": {
"http_code": {
"type": "integer",
"format": "int32",
"description": "Signed fractions of a second at nanosecond resolution of the span\nof time. Durations less than one second are represented with a 0\n`seconds` field and a positive or negative `nanos` field. For durations\nof one second or more, a non-zero value for the `nanos` field must be\nof the same sign as the `seconds` field. Must be from -999,999,999\nto +999,999,999 inclusive."
"format": "int32"
},
"message": {
"type": "string"
},
"http_status": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"$ref": "#/definitions/protobufAny"
}
}
}
}
},
"x-stream-definitions": {
"api_v2GetTraceResponseStream": {
"type": "object",
"properties": {
"result": {
"$ref": "#/definitions/api_v2GetTraceResponseStream"
},
"error": {
"$ref": "#/definitions/runtimeStreamError"
}
},
"description": "A Duration represents a signed, fixed-length span of time represented\nas a count of seconds and fractions of seconds at nanosecond\nresolution. It is independent of any calendar and concepts like \"day\"\nor \"month\". It is related to Timestamp in that the difference between\ntwo Timestamp values is a Duration and it can be added or subtracted\nfrom a Timestamp. Range is approximately +-10,000 years.\n\n# Examples\n\nExample 1: Compute Duration from two Timestamps in pseudo code.\n\n Timestamp start = ...;\n Timestamp end = ...;\n Duration duration = ...;\n\n duration.seconds = end.seconds - start.seconds;\n duration.nanos = end.nanos - start.nanos;\n\n if (duration.seconds \u003c 0 \u0026\u0026 duration.nanos \u003e 0) {\n duration.seconds += 1;\n duration.nanos -= 1000000000;\n } else if (durations.seconds \u003e 0 \u0026\u0026 duration.nanos \u003c 0) {\n duration.seconds -= 1;\n duration.nanos += 1000000000;\n }\n\nExample 2: Compute Timestamp from Timestamp + Duration in pseudo code.\n\n Timestamp start = ...;\n Duration duration = ...;\n Timestamp end = ...;\n\n end.seconds = start.seconds + duration.seconds;\n end.nanos = start.nanos + duration.nanos;\n\n if (end.nanos \u003c 0) {\n end.seconds -= 1;\n end.nanos += 1000000000;\n } else if (end.nanos \u003e= 1000000000) {\n end.seconds += 1;\n end.nanos -= 1000000000;\n }\n\nExample 3: Compute Duration from datetime.timedelta in Python.\n\n td = datetime.timedelta(days=3, minutes=10)\n duration = Duration()\n duration.FromTimedelta(td)\n\n# JSON Mapping\n\nIn JSON format, the Duration type is encoded as a string rather than an\nobject, where the string ends in the suffix \"s\" (indicating seconds) and\nis preceded by the number of seconds, with nanoseconds expressed as\nfractional seconds. For example, 3 seconds with 0 nanoseconds should be\nencoded in JSON format as \"3s\", while 3 seconds and 1 nanosecond should\nbe expressed in JSON format as \"3.000000001s\", and 3 seconds and 1\nmicrosecond should be expressed in JSON format as \"3.000001s\"."
"title": "Stream result of api_v2GetTraceResponseStream"
}
},
"externalDocs": {
"description": "Jaeger API",
"url": "https://github.com/jaegertracing/jaeger"
}
}

0 comments on commit 0ee8357

Please sign in to comment.