diff options
Diffstat (limited to 'vendor/google.golang.org/grpc/health')
-rw-r--r-- | vendor/google.golang.org/grpc/health/client.go | 107 | ||||
-rw-r--r-- | vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go | 263 | ||||
-rw-r--r-- | vendor/google.golang.org/grpc/health/grpc_health_v1/health.proto | 34 | ||||
-rw-r--r-- | vendor/google.golang.org/grpc/health/health.go | 70 | ||||
-rw-r--r-- | vendor/google.golang.org/grpc/health/regenerate.sh | 33 | ||||
-rw-r--r-- | vendor/google.golang.org/grpc/health/server.go | 165 |
6 files changed, 512 insertions, 160 deletions
diff --git a/vendor/google.golang.org/grpc/health/client.go b/vendor/google.golang.org/grpc/health/client.go new file mode 100644 index 0000000..e15f04c --- /dev/null +++ b/vendor/google.golang.org/grpc/health/client.go | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Copyright 2018 gRPC authors. | ||
4 | * | ||
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | * you may not use this file except in compliance with the License. | ||
7 | * You may obtain a copy of the License at | ||
8 | * | ||
9 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | * | ||
11 | * Unless required by applicable law or agreed to in writing, software | ||
12 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | * See the License for the specific language governing permissions and | ||
15 | * limitations under the License. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | package health | ||
20 | |||
21 | import ( | ||
22 | "context" | ||
23 | "fmt" | ||
24 | "io" | ||
25 | "time" | ||
26 | |||
27 | "google.golang.org/grpc" | ||
28 | "google.golang.org/grpc/codes" | ||
29 | healthpb "google.golang.org/grpc/health/grpc_health_v1" | ||
30 | "google.golang.org/grpc/internal" | ||
31 | "google.golang.org/grpc/internal/backoff" | ||
32 | "google.golang.org/grpc/status" | ||
33 | ) | ||
34 | |||
35 | const maxDelay = 120 * time.Second | ||
36 | |||
37 | var backoffStrategy = backoff.Exponential{MaxDelay: maxDelay} | ||
38 | var backoffFunc = func(ctx context.Context, retries int) bool { | ||
39 | d := backoffStrategy.Backoff(retries) | ||
40 | timer := time.NewTimer(d) | ||
41 | select { | ||
42 | case <-timer.C: | ||
43 | return true | ||
44 | case <-ctx.Done(): | ||
45 | timer.Stop() | ||
46 | return false | ||
47 | } | ||
48 | } | ||
49 | |||
50 | func init() { | ||
51 | internal.HealthCheckFunc = clientHealthCheck | ||
52 | } | ||
53 | |||
54 | func clientHealthCheck(ctx context.Context, newStream func() (interface{}, error), reportHealth func(bool), service string) error { | ||
55 | tryCnt := 0 | ||
56 | |||
57 | retryConnection: | ||
58 | for { | ||
59 | // Backs off if the connection has failed in some way without receiving a message in the previous retry. | ||
60 | if tryCnt > 0 && !backoffFunc(ctx, tryCnt-1) { | ||
61 | return nil | ||
62 | } | ||
63 | tryCnt++ | ||
64 | |||
65 | if ctx.Err() != nil { | ||
66 | return nil | ||
67 | } | ||
68 | rawS, err := newStream() | ||
69 | if err != nil { | ||
70 | continue retryConnection | ||
71 | } | ||
72 | |||
73 | s, ok := rawS.(grpc.ClientStream) | ||
74 | // Ideally, this should never happen. But if it happens, the server is marked as healthy for LBing purposes. | ||
75 | if !ok { | ||
76 | reportHealth(true) | ||
77 | return fmt.Errorf("newStream returned %v (type %T); want grpc.ClientStream", rawS, rawS) | ||
78 | } | ||
79 | |||
80 | if err = s.SendMsg(&healthpb.HealthCheckRequest{Service: service}); err != nil && err != io.EOF { | ||
81 | // Stream should have been closed, so we can safely continue to create a new stream. | ||
82 | continue retryConnection | ||
83 | } | ||
84 | s.CloseSend() | ||
85 | |||
86 | resp := new(healthpb.HealthCheckResponse) | ||
87 | for { | ||
88 | err = s.RecvMsg(resp) | ||
89 | |||
90 | // Reports healthy for the LBing purposes if health check is not implemented in the server. | ||
91 | if status.Code(err) == codes.Unimplemented { | ||
92 | reportHealth(true) | ||
93 | return err | ||
94 | } | ||
95 | |||
96 | // Reports unhealthy if server's Watch method gives an error other than UNIMPLEMENTED. | ||
97 | if err != nil { | ||
98 | reportHealth(false) | ||
99 | continue retryConnection | ||
100 | } | ||
101 | |||
102 | // As a message has been received, removes the need for backoff for the next retry by reseting the try count. | ||
103 | tryCnt = 0 | ||
104 | reportHealth(resp.Status == healthpb.HealthCheckResponse_SERVING) | ||
105 | } | ||
106 | } | ||
107 | } | ||
diff --git a/vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go b/vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go index 89c4d45..c2f2c77 100644 --- a/vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go +++ b/vendor/google.golang.org/grpc/health/grpc_health_v1/health.pb.go | |||
@@ -1,18 +1,7 @@ | |||
1 | // Code generated by protoc-gen-go. | 1 | // Code generated by protoc-gen-go. DO NOT EDIT. |
2 | // source: health.proto | 2 | // source: grpc/health/v1/health.proto |
3 | // DO NOT EDIT! | ||
4 | 3 | ||
5 | /* | 4 | package grpc_health_v1 // import "google.golang.org/grpc/health/grpc_health_v1" |
6 | Package grpc_health_v1 is a generated protocol buffer package. | ||
7 | |||
8 | It is generated from these files: | ||
9 | health.proto | ||
10 | |||
11 | It has these top-level messages: | ||
12 | HealthCheckRequest | ||
13 | HealthCheckResponse | ||
14 | */ | ||
15 | package grpc_health_v1 | ||
16 | 5 | ||
17 | import proto "github.com/golang/protobuf/proto" | 6 | import proto "github.com/golang/protobuf/proto" |
18 | import fmt "fmt" | 7 | import fmt "fmt" |
@@ -37,46 +26,107 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package | |||
37 | type HealthCheckResponse_ServingStatus int32 | 26 | type HealthCheckResponse_ServingStatus int32 |
38 | 27 | ||
39 | const ( | 28 | const ( |
40 | HealthCheckResponse_UNKNOWN HealthCheckResponse_ServingStatus = 0 | 29 | HealthCheckResponse_UNKNOWN HealthCheckResponse_ServingStatus = 0 |
41 | HealthCheckResponse_SERVING HealthCheckResponse_ServingStatus = 1 | 30 | HealthCheckResponse_SERVING HealthCheckResponse_ServingStatus = 1 |
42 | HealthCheckResponse_NOT_SERVING HealthCheckResponse_ServingStatus = 2 | 31 | HealthCheckResponse_NOT_SERVING HealthCheckResponse_ServingStatus = 2 |
32 | HealthCheckResponse_SERVICE_UNKNOWN HealthCheckResponse_ServingStatus = 3 | ||
43 | ) | 33 | ) |
44 | 34 | ||
45 | var HealthCheckResponse_ServingStatus_name = map[int32]string{ | 35 | var HealthCheckResponse_ServingStatus_name = map[int32]string{ |
46 | 0: "UNKNOWN", | 36 | 0: "UNKNOWN", |
47 | 1: "SERVING", | 37 | 1: "SERVING", |
48 | 2: "NOT_SERVING", | 38 | 2: "NOT_SERVING", |
39 | 3: "SERVICE_UNKNOWN", | ||
49 | } | 40 | } |
50 | var HealthCheckResponse_ServingStatus_value = map[string]int32{ | 41 | var HealthCheckResponse_ServingStatus_value = map[string]int32{ |
51 | "UNKNOWN": 0, | 42 | "UNKNOWN": 0, |
52 | "SERVING": 1, | 43 | "SERVING": 1, |
53 | "NOT_SERVING": 2, | 44 | "NOT_SERVING": 2, |
45 | "SERVICE_UNKNOWN": 3, | ||
54 | } | 46 | } |
55 | 47 | ||
56 | func (x HealthCheckResponse_ServingStatus) String() string { | 48 | func (x HealthCheckResponse_ServingStatus) String() string { |
57 | return proto.EnumName(HealthCheckResponse_ServingStatus_name, int32(x)) | 49 | return proto.EnumName(HealthCheckResponse_ServingStatus_name, int32(x)) |
58 | } | 50 | } |
59 | func (HealthCheckResponse_ServingStatus) EnumDescriptor() ([]byte, []int) { | 51 | func (HealthCheckResponse_ServingStatus) EnumDescriptor() ([]byte, []int) { |
60 | return fileDescriptor0, []int{1, 0} | 52 | return fileDescriptor_health_6b1a06aa67f91efd, []int{1, 0} |
61 | } | 53 | } |
62 | 54 | ||
63 | type HealthCheckRequest struct { | 55 | type HealthCheckRequest struct { |
64 | Service string `protobuf:"bytes,1,opt,name=service" json:"service,omitempty"` | 56 | Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` |
57 | XXX_NoUnkeyedLiteral struct{} `json:"-"` | ||
58 | XXX_unrecognized []byte `json:"-"` | ||
59 | XXX_sizecache int32 `json:"-"` | ||
60 | } | ||
61 | |||
62 | func (m *HealthCheckRequest) Reset() { *m = HealthCheckRequest{} } | ||
63 | func (m *HealthCheckRequest) String() string { return proto.CompactTextString(m) } | ||
64 | func (*HealthCheckRequest) ProtoMessage() {} | ||
65 | func (*HealthCheckRequest) Descriptor() ([]byte, []int) { | ||
66 | return fileDescriptor_health_6b1a06aa67f91efd, []int{0} | ||
67 | } | ||
68 | func (m *HealthCheckRequest) XXX_Unmarshal(b []byte) error { | ||
69 | return xxx_messageInfo_HealthCheckRequest.Unmarshal(m, b) | ||
70 | } | ||
71 | func (m *HealthCheckRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | ||
72 | return xxx_messageInfo_HealthCheckRequest.Marshal(b, m, deterministic) | ||
73 | } | ||
74 | func (dst *HealthCheckRequest) XXX_Merge(src proto.Message) { | ||
75 | xxx_messageInfo_HealthCheckRequest.Merge(dst, src) | ||
76 | } | ||
77 | func (m *HealthCheckRequest) XXX_Size() int { | ||
78 | return xxx_messageInfo_HealthCheckRequest.Size(m) | ||
79 | } | ||
80 | func (m *HealthCheckRequest) XXX_DiscardUnknown() { | ||
81 | xxx_messageInfo_HealthCheckRequest.DiscardUnknown(m) | ||
65 | } | 82 | } |
66 | 83 | ||
67 | func (m *HealthCheckRequest) Reset() { *m = HealthCheckRequest{} } | 84 | var xxx_messageInfo_HealthCheckRequest proto.InternalMessageInfo |
68 | func (m *HealthCheckRequest) String() string { return proto.CompactTextString(m) } | 85 | |
69 | func (*HealthCheckRequest) ProtoMessage() {} | 86 | func (m *HealthCheckRequest) GetService() string { |
70 | func (*HealthCheckRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } | 87 | if m != nil { |
88 | return m.Service | ||
89 | } | ||
90 | return "" | ||
91 | } | ||
71 | 92 | ||
72 | type HealthCheckResponse struct { | 93 | type HealthCheckResponse struct { |
73 | Status HealthCheckResponse_ServingStatus `protobuf:"varint,1,opt,name=status,enum=grpc.health.v1.HealthCheckResponse_ServingStatus" json:"status,omitempty"` | 94 | Status HealthCheckResponse_ServingStatus `protobuf:"varint,1,opt,name=status,proto3,enum=grpc.health.v1.HealthCheckResponse_ServingStatus" json:"status,omitempty"` |
95 | XXX_NoUnkeyedLiteral struct{} `json:"-"` | ||
96 | XXX_unrecognized []byte `json:"-"` | ||
97 | XXX_sizecache int32 `json:"-"` | ||
74 | } | 98 | } |
75 | 99 | ||
76 | func (m *HealthCheckResponse) Reset() { *m = HealthCheckResponse{} } | 100 | func (m *HealthCheckResponse) Reset() { *m = HealthCheckResponse{} } |
77 | func (m *HealthCheckResponse) String() string { return proto.CompactTextString(m) } | 101 | func (m *HealthCheckResponse) String() string { return proto.CompactTextString(m) } |
78 | func (*HealthCheckResponse) ProtoMessage() {} | 102 | func (*HealthCheckResponse) ProtoMessage() {} |
79 | func (*HealthCheckResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } | 103 | func (*HealthCheckResponse) Descriptor() ([]byte, []int) { |
104 | return fileDescriptor_health_6b1a06aa67f91efd, []int{1} | ||
105 | } | ||
106 | func (m *HealthCheckResponse) XXX_Unmarshal(b []byte) error { | ||
107 | return xxx_messageInfo_HealthCheckResponse.Unmarshal(m, b) | ||
108 | } | ||
109 | func (m *HealthCheckResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | ||
110 | return xxx_messageInfo_HealthCheckResponse.Marshal(b, m, deterministic) | ||
111 | } | ||
112 | func (dst *HealthCheckResponse) XXX_Merge(src proto.Message) { | ||
113 | xxx_messageInfo_HealthCheckResponse.Merge(dst, src) | ||
114 | } | ||
115 | func (m *HealthCheckResponse) XXX_Size() int { | ||
116 | return xxx_messageInfo_HealthCheckResponse.Size(m) | ||
117 | } | ||
118 | func (m *HealthCheckResponse) XXX_DiscardUnknown() { | ||
119 | xxx_messageInfo_HealthCheckResponse.DiscardUnknown(m) | ||
120 | } | ||
121 | |||
122 | var xxx_messageInfo_HealthCheckResponse proto.InternalMessageInfo | ||
123 | |||
124 | func (m *HealthCheckResponse) GetStatus() HealthCheckResponse_ServingStatus { | ||
125 | if m != nil { | ||
126 | return m.Status | ||
127 | } | ||
128 | return HealthCheckResponse_UNKNOWN | ||
129 | } | ||
80 | 130 | ||
81 | func init() { | 131 | func init() { |
82 | proto.RegisterType((*HealthCheckRequest)(nil), "grpc.health.v1.HealthCheckRequest") | 132 | proto.RegisterType((*HealthCheckRequest)(nil), "grpc.health.v1.HealthCheckRequest") |
@@ -92,10 +142,29 @@ var _ grpc.ClientConn | |||
92 | // is compatible with the grpc package it is being compiled against. | 142 | // is compatible with the grpc package it is being compiled against. |
93 | const _ = grpc.SupportPackageIsVersion4 | 143 | const _ = grpc.SupportPackageIsVersion4 |
94 | 144 | ||
95 | // Client API for Health service | 145 | // HealthClient is the client API for Health service. |
96 | 146 | // | |
147 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. | ||
97 | type HealthClient interface { | 148 | type HealthClient interface { |
149 | // If the requested service is unknown, the call will fail with status | ||
150 | // NOT_FOUND. | ||
98 | Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) | 151 | Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) |
152 | // Performs a watch for the serving status of the requested service. | ||
153 | // The server will immediately send back a message indicating the current | ||
154 | // serving status. It will then subsequently send a new message whenever | ||
155 | // the service's serving status changes. | ||
156 | // | ||
157 | // If the requested service is unknown when the call is received, the | ||
158 | // server will send a message setting the serving status to | ||
159 | // SERVICE_UNKNOWN but will *not* terminate the call. If at some | ||
160 | // future point, the serving status of the service becomes known, the | ||
161 | // server will send a new message with the service's serving status. | ||
162 | // | ||
163 | // If the call terminates with status UNIMPLEMENTED, then clients | ||
164 | // should assume this method is not supported and should not retry the | ||
165 | // call. If the call terminates with any other status (including OK), | ||
166 | // clients should retry the call with appropriate exponential backoff. | ||
167 | Watch(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (Health_WatchClient, error) | ||
99 | } | 168 | } |
100 | 169 | ||
101 | type healthClient struct { | 170 | type healthClient struct { |
@@ -108,17 +177,66 @@ func NewHealthClient(cc *grpc.ClientConn) HealthClient { | |||
108 | 177 | ||
109 | func (c *healthClient) Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) { | 178 | func (c *healthClient) Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) { |
110 | out := new(HealthCheckResponse) | 179 | out := new(HealthCheckResponse) |
111 | err := grpc.Invoke(ctx, "/grpc.health.v1.Health/Check", in, out, c.cc, opts...) | 180 | err := c.cc.Invoke(ctx, "/grpc.health.v1.Health/Check", in, out, opts...) |
112 | if err != nil { | 181 | if err != nil { |
113 | return nil, err | 182 | return nil, err |
114 | } | 183 | } |
115 | return out, nil | 184 | return out, nil |
116 | } | 185 | } |
117 | 186 | ||
118 | // Server API for Health service | 187 | func (c *healthClient) Watch(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (Health_WatchClient, error) { |
188 | stream, err := c.cc.NewStream(ctx, &_Health_serviceDesc.Streams[0], "/grpc.health.v1.Health/Watch", opts...) | ||
189 | if err != nil { | ||
190 | return nil, err | ||
191 | } | ||
192 | x := &healthWatchClient{stream} | ||
193 | if err := x.ClientStream.SendMsg(in); err != nil { | ||
194 | return nil, err | ||
195 | } | ||
196 | if err := x.ClientStream.CloseSend(); err != nil { | ||
197 | return nil, err | ||
198 | } | ||
199 | return x, nil | ||
200 | } | ||
201 | |||
202 | type Health_WatchClient interface { | ||
203 | Recv() (*HealthCheckResponse, error) | ||
204 | grpc.ClientStream | ||
205 | } | ||
206 | |||
207 | type healthWatchClient struct { | ||
208 | grpc.ClientStream | ||
209 | } | ||
119 | 210 | ||
211 | func (x *healthWatchClient) Recv() (*HealthCheckResponse, error) { | ||
212 | m := new(HealthCheckResponse) | ||
213 | if err := x.ClientStream.RecvMsg(m); err != nil { | ||
214 | return nil, err | ||
215 | } | ||
216 | return m, nil | ||
217 | } | ||
218 | |||
219 | // HealthServer is the server API for Health service. | ||
120 | type HealthServer interface { | 220 | type HealthServer interface { |
221 | // If the requested service is unknown, the call will fail with status | ||
222 | // NOT_FOUND. | ||
121 | Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) | 223 | Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) |
224 | // Performs a watch for the serving status of the requested service. | ||
225 | // The server will immediately send back a message indicating the current | ||
226 | // serving status. It will then subsequently send a new message whenever | ||
227 | // the service's serving status changes. | ||
228 | // | ||
229 | // If the requested service is unknown when the call is received, the | ||
230 | // server will send a message setting the serving status to | ||
231 | // SERVICE_UNKNOWN but will *not* terminate the call. If at some | ||
232 | // future point, the serving status of the service becomes known, the | ||
233 | // server will send a new message with the service's serving status. | ||
234 | // | ||
235 | // If the call terminates with status UNIMPLEMENTED, then clients | ||
236 | // should assume this method is not supported and should not retry the | ||
237 | // call. If the call terminates with any other status (including OK), | ||
238 | // clients should retry the call with appropriate exponential backoff. | ||
239 | Watch(*HealthCheckRequest, Health_WatchServer) error | ||
122 | } | 240 | } |
123 | 241 | ||
124 | func RegisterHealthServer(s *grpc.Server, srv HealthServer) { | 242 | func RegisterHealthServer(s *grpc.Server, srv HealthServer) { |
@@ -143,6 +261,27 @@ func _Health_Check_Handler(srv interface{}, ctx context.Context, dec func(interf | |||
143 | return interceptor(ctx, in, info, handler) | 261 | return interceptor(ctx, in, info, handler) |
144 | } | 262 | } |
145 | 263 | ||
264 | func _Health_Watch_Handler(srv interface{}, stream grpc.ServerStream) error { | ||
265 | m := new(HealthCheckRequest) | ||
266 | if err := stream.RecvMsg(m); err != nil { | ||
267 | return err | ||
268 | } | ||
269 | return srv.(HealthServer).Watch(m, &healthWatchServer{stream}) | ||
270 | } | ||
271 | |||
272 | type Health_WatchServer interface { | ||
273 | Send(*HealthCheckResponse) error | ||
274 | grpc.ServerStream | ||
275 | } | ||
276 | |||
277 | type healthWatchServer struct { | ||
278 | grpc.ServerStream | ||
279 | } | ||
280 | |||
281 | func (x *healthWatchServer) Send(m *HealthCheckResponse) error { | ||
282 | return x.ServerStream.SendMsg(m) | ||
283 | } | ||
284 | |||
146 | var _Health_serviceDesc = grpc.ServiceDesc{ | 285 | var _Health_serviceDesc = grpc.ServiceDesc{ |
147 | ServiceName: "grpc.health.v1.Health", | 286 | ServiceName: "grpc.health.v1.Health", |
148 | HandlerType: (*HealthServer)(nil), | 287 | HandlerType: (*HealthServer)(nil), |
@@ -152,25 +291,37 @@ var _Health_serviceDesc = grpc.ServiceDesc{ | |||
152 | Handler: _Health_Check_Handler, | 291 | Handler: _Health_Check_Handler, |
153 | }, | 292 | }, |
154 | }, | 293 | }, |
155 | Streams: []grpc.StreamDesc{}, | 294 | Streams: []grpc.StreamDesc{ |
156 | Metadata: "health.proto", | 295 | { |
157 | } | 296 | StreamName: "Watch", |
158 | 297 | Handler: _Health_Watch_Handler, | |
159 | func init() { proto.RegisterFile("health.proto", fileDescriptor0) } | 298 | ServerStreams: true, |
160 | 299 | }, | |
161 | var fileDescriptor0 = []byte{ | 300 | }, |
162 | // 204 bytes of a gzipped FileDescriptorProto | 301 | Metadata: "grpc/health/v1/health.proto", |
163 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0xc9, 0x48, 0x4d, 0xcc, | 302 | } |
164 | 0x29, 0xc9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4b, 0x2f, 0x2a, 0x48, 0xd6, 0x83, | 303 | |
165 | 0x0a, 0x95, 0x19, 0x2a, 0xe9, 0x71, 0x09, 0x79, 0x80, 0x39, 0xce, 0x19, 0xa9, 0xc9, 0xd9, 0x41, | 304 | func init() { proto.RegisterFile("grpc/health/v1/health.proto", fileDescriptor_health_6b1a06aa67f91efd) } |
166 | 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x12, 0x5c, 0xec, 0xc5, 0xa9, 0x45, 0x65, 0x99, 0xc9, | 305 | |
167 | 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x30, 0xae, 0xd2, 0x1c, 0x46, 0x2e, 0x61, 0x14, | 306 | var fileDescriptor_health_6b1a06aa67f91efd = []byte{ |
168 | 0x0d, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x42, 0x9e, 0x5c, 0x6c, 0xc5, 0x25, 0x89, 0x25, 0xa5, | 307 | // 297 bytes of a gzipped FileDescriptorProto |
169 | 0xc5, 0x60, 0x0d, 0x7c, 0x46, 0x86, 0x7a, 0xa8, 0x16, 0xe9, 0x61, 0xd1, 0xa4, 0x17, 0x0c, 0x32, | 308 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4e, 0x2f, 0x2a, 0x48, |
170 | 0x34, 0x2f, 0x3d, 0x18, 0xac, 0x31, 0x08, 0x6a, 0x80, 0x92, 0x15, 0x17, 0x2f, 0x8a, 0x84, 0x10, | 309 | 0xd6, 0xcf, 0x48, 0x4d, 0xcc, 0x29, 0xc9, 0xd0, 0x2f, 0x33, 0x84, 0xb2, 0xf4, 0x0a, 0x8a, 0xf2, |
171 | 0x37, 0x17, 0x7b, 0xa8, 0x9f, 0xb7, 0x9f, 0x7f, 0xb8, 0x9f, 0x00, 0x03, 0x88, 0x13, 0xec, 0x1a, | 310 | 0x4b, 0xf2, 0x85, 0xf8, 0x40, 0x92, 0x7a, 0x50, 0xa1, 0x32, 0x43, 0x25, 0x3d, 0x2e, 0x21, 0x0f, |
172 | 0x14, 0xe6, 0xe9, 0xe7, 0x2e, 0xc0, 0x28, 0xc4, 0xcf, 0xc5, 0xed, 0xe7, 0x1f, 0x12, 0x0f, 0x13, | 311 | 0x30, 0xc7, 0x39, 0x23, 0x35, 0x39, 0x3b, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0x48, 0x82, |
173 | 0x60, 0x32, 0x8a, 0xe2, 0x62, 0x83, 0x58, 0x24, 0x14, 0xc0, 0xc5, 0x0a, 0xb6, 0x4c, 0x48, 0x09, | 312 | 0x8b, 0xbd, 0x38, 0xb5, 0xa8, 0x2c, 0x33, 0x39, 0x55, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x08, |
174 | 0xaf, 0x4b, 0xc0, 0xfe, 0x95, 0x52, 0x26, 0xc2, 0xb5, 0x49, 0x6c, 0xe0, 0x10, 0x34, 0x06, 0x04, | 313 | 0xc6, 0x55, 0xda, 0xc8, 0xc8, 0x25, 0x8c, 0xa2, 0xa1, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0xc8, |
175 | 0x00, 0x00, 0xff, 0xff, 0xac, 0x56, 0x2a, 0xcb, 0x51, 0x01, 0x00, 0x00, | 314 | 0x93, 0x8b, 0xad, 0xb8, 0x24, 0xb1, 0xa4, 0xb4, 0x18, 0xac, 0x81, 0xcf, 0xc8, 0x50, 0x0f, 0xd5, |
315 | 0x22, 0x3d, 0x2c, 0x9a, 0xf4, 0x82, 0x41, 0x86, 0xe6, 0xa5, 0x07, 0x83, 0x35, 0x06, 0x41, 0x0d, | ||
316 | 0x50, 0xf2, 0xe7, 0xe2, 0x45, 0x91, 0x10, 0xe2, 0xe6, 0x62, 0x0f, 0xf5, 0xf3, 0xf6, 0xf3, 0x0f, | ||
317 | 0xf7, 0x13, 0x60, 0x00, 0x71, 0x82, 0x5d, 0x83, 0xc2, 0x3c, 0xfd, 0xdc, 0x05, 0x18, 0x85, 0xf8, | ||
318 | 0xb9, 0xb8, 0xfd, 0xfc, 0x43, 0xe2, 0x61, 0x02, 0x4c, 0x42, 0xc2, 0x5c, 0xfc, 0x60, 0x8e, 0xb3, | ||
319 | 0x6b, 0x3c, 0x4c, 0x0b, 0xb3, 0xd1, 0x3a, 0x46, 0x2e, 0x36, 0x88, 0xf5, 0x42, 0x01, 0x5c, 0xac, | ||
320 | 0x60, 0x27, 0x08, 0x29, 0xe1, 0x75, 0x1f, 0x38, 0x14, 0xa4, 0x94, 0x89, 0xf0, 0x83, 0x50, 0x10, | ||
321 | 0x17, 0x6b, 0x78, 0x62, 0x49, 0x72, 0x06, 0xd5, 0x4c, 0x34, 0x60, 0x74, 0x4a, 0xe4, 0x12, 0xcc, | ||
322 | 0xcc, 0x47, 0x53, 0xea, 0xc4, 0x0d, 0x51, 0x1b, 0x00, 0x8a, 0xc6, 0x00, 0xc6, 0x28, 0x9d, 0xf4, | ||
323 | 0xfc, 0xfc, 0xf4, 0x9c, 0x54, 0xbd, 0xf4, 0xfc, 0x9c, 0xc4, 0xbc, 0x74, 0xbd, 0xfc, 0xa2, 0x74, | ||
324 | 0x7d, 0xe4, 0x78, 0x07, 0xb1, 0xe3, 0x21, 0xec, 0xf8, 0x32, 0xc3, 0x55, 0x4c, 0x7c, 0xee, 0x20, | ||
325 | 0xd3, 0x20, 0x46, 0xe8, 0x85, 0x19, 0x26, 0xb1, 0x81, 0x93, 0x83, 0x31, 0x20, 0x00, 0x00, 0xff, | ||
326 | 0xff, 0x12, 0x7d, 0x96, 0xcb, 0x2d, 0x02, 0x00, 0x00, | ||
176 | } | 327 | } |
diff --git a/vendor/google.golang.org/grpc/health/grpc_health_v1/health.proto b/vendor/google.golang.org/grpc/health/grpc_health_v1/health.proto deleted file mode 100644 index 6072fdc..0000000 --- a/vendor/google.golang.org/grpc/health/grpc_health_v1/health.proto +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | // Copyright 2017 gRPC authors. | ||
2 | // | ||
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | // you may not use this file except in compliance with the License. | ||
5 | // You may obtain a copy of the License at | ||
6 | // | ||
7 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | // | ||
9 | // Unless required by applicable law or agreed to in writing, software | ||
10 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | // See the License for the specific language governing permissions and | ||
13 | // limitations under the License. | ||
14 | |||
15 | syntax = "proto3"; | ||
16 | |||
17 | package grpc.health.v1; | ||
18 | |||
19 | message HealthCheckRequest { | ||
20 | string service = 1; | ||
21 | } | ||
22 | |||
23 | message HealthCheckResponse { | ||
24 | enum ServingStatus { | ||
25 | UNKNOWN = 0; | ||
26 | SERVING = 1; | ||
27 | NOT_SERVING = 2; | ||
28 | } | ||
29 | ServingStatus status = 1; | ||
30 | } | ||
31 | |||
32 | service Health{ | ||
33 | rpc Check(HealthCheckRequest) returns (HealthCheckResponse); | ||
34 | } | ||
diff --git a/vendor/google.golang.org/grpc/health/health.go b/vendor/google.golang.org/grpc/health/health.go deleted file mode 100644 index 4dccbc7..0000000 --- a/vendor/google.golang.org/grpc/health/health.go +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Copyright 2017 gRPC authors. | ||
4 | * | ||
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | * you may not use this file except in compliance with the License. | ||
7 | * You may obtain a copy of the License at | ||
8 | * | ||
9 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | * | ||
11 | * Unless required by applicable law or agreed to in writing, software | ||
12 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | * See the License for the specific language governing permissions and | ||
15 | * limitations under the License. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | // Package health provides some utility functions to health-check a server. The implementation | ||
20 | // is based on protobuf. Users need to write their own implementations if other IDLs are used. | ||
21 | package health | ||
22 | |||
23 | import ( | ||
24 | "sync" | ||
25 | |||
26 | "golang.org/x/net/context" | ||
27 | "google.golang.org/grpc" | ||
28 | "google.golang.org/grpc/codes" | ||
29 | healthpb "google.golang.org/grpc/health/grpc_health_v1" | ||
30 | ) | ||
31 | |||
32 | // Server implements `service Health`. | ||
33 | type Server struct { | ||
34 | mu sync.Mutex | ||
35 | // statusMap stores the serving status of the services this Server monitors. | ||
36 | statusMap map[string]healthpb.HealthCheckResponse_ServingStatus | ||
37 | } | ||
38 | |||
39 | // NewServer returns a new Server. | ||
40 | func NewServer() *Server { | ||
41 | return &Server{ | ||
42 | statusMap: make(map[string]healthpb.HealthCheckResponse_ServingStatus), | ||
43 | } | ||
44 | } | ||
45 | |||
46 | // Check implements `service Health`. | ||
47 | func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { | ||
48 | s.mu.Lock() | ||
49 | defer s.mu.Unlock() | ||
50 | if in.Service == "" { | ||
51 | // check the server overall health status. | ||
52 | return &healthpb.HealthCheckResponse{ | ||
53 | Status: healthpb.HealthCheckResponse_SERVING, | ||
54 | }, nil | ||
55 | } | ||
56 | if status, ok := s.statusMap[in.Service]; ok { | ||
57 | return &healthpb.HealthCheckResponse{ | ||
58 | Status: status, | ||
59 | }, nil | ||
60 | } | ||
61 | return nil, grpc.Errorf(codes.NotFound, "unknown service") | ||
62 | } | ||
63 | |||
64 | // SetServingStatus is called when need to reset the serving status of a service | ||
65 | // or insert a new service entry into the statusMap. | ||
66 | func (s *Server) SetServingStatus(service string, status healthpb.HealthCheckResponse_ServingStatus) { | ||
67 | s.mu.Lock() | ||
68 | s.statusMap[service] = status | ||
69 | s.mu.Unlock() | ||
70 | } | ||
diff --git a/vendor/google.golang.org/grpc/health/regenerate.sh b/vendor/google.golang.org/grpc/health/regenerate.sh new file mode 100644 index 0000000..b11eccb --- /dev/null +++ b/vendor/google.golang.org/grpc/health/regenerate.sh | |||
@@ -0,0 +1,33 @@ | |||
1 | #!/bin/bash | ||
2 | # Copyright 2018 gRPC authors. | ||
3 | # | ||
4 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | # you may not use this file except in compliance with the License. | ||
6 | # You may obtain a copy of the License at | ||
7 | # | ||
8 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | # | ||
10 | # Unless required by applicable law or agreed to in writing, software | ||
11 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | # See the License for the specific language governing permissions and | ||
14 | # limitations under the License. | ||
15 | |||
16 | set -eux -o pipefail | ||
17 | |||
18 | TMP=$(mktemp -d) | ||
19 | |||
20 | function finish { | ||
21 | rm -rf "$TMP" | ||
22 | } | ||
23 | trap finish EXIT | ||
24 | |||
25 | pushd "$TMP" | ||
26 | mkdir -p grpc/health/v1 | ||
27 | curl https://raw.githubusercontent.com/grpc/grpc-proto/master/grpc/health/v1/health.proto > grpc/health/v1/health.proto | ||
28 | |||
29 | protoc --go_out=plugins=grpc,paths=source_relative:. -I. grpc/health/v1/*.proto | ||
30 | popd | ||
31 | rm -f grpc_health_v1/*.pb.go | ||
32 | cp "$TMP"/grpc/health/v1/*.pb.go grpc_health_v1/ | ||
33 | |||
diff --git a/vendor/google.golang.org/grpc/health/server.go b/vendor/google.golang.org/grpc/health/server.go new file mode 100644 index 0000000..c79f9d2 --- /dev/null +++ b/vendor/google.golang.org/grpc/health/server.go | |||
@@ -0,0 +1,165 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Copyright 2017 gRPC authors. | ||
4 | * | ||
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | * you may not use this file except in compliance with the License. | ||
7 | * You may obtain a copy of the License at | ||
8 | * | ||
9 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | * | ||
11 | * Unless required by applicable law or agreed to in writing, software | ||
12 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | * See the License for the specific language governing permissions and | ||
15 | * limitations under the License. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | //go:generate ./regenerate.sh | ||
20 | |||
21 | // Package health provides a service that exposes server's health and it must be | ||
22 | // imported to enable support for client-side health checks. | ||
23 | package health | ||
24 | |||
25 | import ( | ||
26 | "context" | ||
27 | "sync" | ||
28 | |||
29 | "google.golang.org/grpc/codes" | ||
30 | "google.golang.org/grpc/grpclog" | ||
31 | healthgrpc "google.golang.org/grpc/health/grpc_health_v1" | ||
32 | healthpb "google.golang.org/grpc/health/grpc_health_v1" | ||
33 | "google.golang.org/grpc/status" | ||
34 | ) | ||
35 | |||
36 | // Server implements `service Health`. | ||
37 | type Server struct { | ||
38 | mu sync.Mutex | ||
39 | // If shutdown is true, it's expected all serving status is NOT_SERVING, and | ||
40 | // will stay in NOT_SERVING. | ||
41 | shutdown bool | ||
42 | // statusMap stores the serving status of the services this Server monitors. | ||
43 | statusMap map[string]healthpb.HealthCheckResponse_ServingStatus | ||
44 | updates map[string]map[healthgrpc.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus | ||
45 | } | ||
46 | |||
47 | // NewServer returns a new Server. | ||
48 | func NewServer() *Server { | ||
49 | return &Server{ | ||
50 | statusMap: map[string]healthpb.HealthCheckResponse_ServingStatus{"": healthpb.HealthCheckResponse_SERVING}, | ||
51 | updates: make(map[string]map[healthgrpc.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus), | ||
52 | } | ||
53 | } | ||
54 | |||
55 | // Check implements `service Health`. | ||
56 | func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { | ||
57 | s.mu.Lock() | ||
58 | defer s.mu.Unlock() | ||
59 | if servingStatus, ok := s.statusMap[in.Service]; ok { | ||
60 | return &healthpb.HealthCheckResponse{ | ||
61 | Status: servingStatus, | ||
62 | }, nil | ||
63 | } | ||
64 | return nil, status.Error(codes.NotFound, "unknown service") | ||
65 | } | ||
66 | |||
67 | // Watch implements `service Health`. | ||
68 | func (s *Server) Watch(in *healthpb.HealthCheckRequest, stream healthgrpc.Health_WatchServer) error { | ||
69 | service := in.Service | ||
70 | // update channel is used for getting service status updates. | ||
71 | update := make(chan healthpb.HealthCheckResponse_ServingStatus, 1) | ||
72 | s.mu.Lock() | ||
73 | // Puts the initial status to the channel. | ||
74 | if servingStatus, ok := s.statusMap[service]; ok { | ||
75 | update <- servingStatus | ||
76 | } else { | ||
77 | update <- healthpb.HealthCheckResponse_SERVICE_UNKNOWN | ||
78 | } | ||
79 | |||
80 | // Registers the update channel to the correct place in the updates map. | ||
81 | if _, ok := s.updates[service]; !ok { | ||
82 | s.updates[service] = make(map[healthgrpc.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus) | ||
83 | } | ||
84 | s.updates[service][stream] = update | ||
85 | defer func() { | ||
86 | s.mu.Lock() | ||
87 | delete(s.updates[service], stream) | ||
88 | s.mu.Unlock() | ||
89 | }() | ||
90 | s.mu.Unlock() | ||
91 | |||
92 | var lastSentStatus healthpb.HealthCheckResponse_ServingStatus = -1 | ||
93 | for { | ||
94 | select { | ||
95 | // Status updated. Sends the up-to-date status to the client. | ||
96 | case servingStatus := <-update: | ||
97 | if lastSentStatus == servingStatus { | ||
98 | continue | ||
99 | } | ||
100 | lastSentStatus = servingStatus | ||
101 | err := stream.Send(&healthpb.HealthCheckResponse{Status: servingStatus}) | ||
102 | if err != nil { | ||
103 | return status.Error(codes.Canceled, "Stream has ended.") | ||
104 | } | ||
105 | // Context done. Removes the update channel from the updates map. | ||
106 | case <-stream.Context().Done(): | ||
107 | return status.Error(codes.Canceled, "Stream has ended.") | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | |||
112 | // SetServingStatus is called when need to reset the serving status of a service | ||
113 | // or insert a new service entry into the statusMap. | ||
114 | func (s *Server) SetServingStatus(service string, servingStatus healthpb.HealthCheckResponse_ServingStatus) { | ||
115 | s.mu.Lock() | ||
116 | defer s.mu.Unlock() | ||
117 | if s.shutdown { | ||
118 | grpclog.Infof("health: status changing for %s to %v is ignored because health service is shutdown", service, servingStatus) | ||
119 | return | ||
120 | } | ||
121 | |||
122 | s.setServingStatusLocked(service, servingStatus) | ||
123 | } | ||
124 | |||
125 | func (s *Server) setServingStatusLocked(service string, servingStatus healthpb.HealthCheckResponse_ServingStatus) { | ||
126 | s.statusMap[service] = servingStatus | ||
127 | for _, update := range s.updates[service] { | ||
128 | // Clears previous updates, that are not sent to the client, from the channel. | ||
129 | // This can happen if the client is not reading and the server gets flow control limited. | ||
130 | select { | ||
131 | case <-update: | ||
132 | default: | ||
133 | } | ||
134 | // Puts the most recent update to the channel. | ||
135 | update <- servingStatus | ||
136 | } | ||
137 | } | ||
138 | |||
139 | // Shutdown sets all serving status to NOT_SERVING, and configures the server to | ||
140 | // ignore all future status changes. | ||
141 | // | ||
142 | // This changes serving status for all services. To set status for a perticular | ||
143 | // services, call SetServingStatus(). | ||
144 | func (s *Server) Shutdown() { | ||
145 | s.mu.Lock() | ||
146 | defer s.mu.Unlock() | ||
147 | s.shutdown = true | ||
148 | for service := range s.statusMap { | ||
149 | s.setServingStatusLocked(service, healthpb.HealthCheckResponse_NOT_SERVING) | ||
150 | } | ||
151 | } | ||
152 | |||
153 | // Resume sets all serving status to SERVING, and configures the server to | ||
154 | // accept all future status changes. | ||
155 | // | ||
156 | // This changes serving status for all services. To set status for a perticular | ||
157 | // services, call SetServingStatus(). | ||
158 | func (s *Server) Resume() { | ||
159 | s.mu.Lock() | ||
160 | defer s.mu.Unlock() | ||
161 | s.shutdown = false | ||
162 | for service := range s.statusMap { | ||
163 | s.setServingStatusLocked(service, healthpb.HealthCheckResponse_SERVING) | ||
164 | } | ||
165 | } | ||