1
1
package org .hypertrace .gateway .service ;
2
2
3
3
import com .google .common .base .Preconditions ;
4
+ import com .google .common .collect .ImmutableMap ;
4
5
import com .google .protobuf .ServiceException ;
5
6
import com .typesafe .config .Config ;
6
7
import io .grpc .ManagedChannel ;
7
8
import io .grpc .ManagedChannelBuilder ;
8
9
import io .grpc .stub .StreamObserver ;
10
+ import io .micrometer .core .instrument .Counter ;
9
11
import java .util .Optional ;
10
12
import java .util .concurrent .ExecutorService ;
11
13
import org .apache .commons .lang3 .StringUtils ;
12
14
import org .hypertrace .core .attribute .service .client .AttributeServiceClient ;
13
15
import org .hypertrace .core .attribute .service .client .config .AttributeServiceClientConfig ;
14
16
import org .hypertrace .core .query .service .client .QueryServiceClient ;
15
17
import org .hypertrace .core .query .service .client .QueryServiceConfig ;
18
+ import org .hypertrace .core .serviceframework .metrics .PlatformMetricsRegistry ;
16
19
import org .hypertrace .entity .query .service .client .EntityQueryServiceClient ;
17
20
import org .hypertrace .entity .service .client .config .EntityServiceClientConfig ;
18
21
import org .hypertrace .gateway .service .baseline .BaselineService ;
@@ -61,6 +64,11 @@ public class GatewayServiceImpl extends GatewayServiceGrpc.GatewayServiceImplBas
61
64
private static final String REQUEST_TIMEOUT_CONFIG_KEY = "request.timeout" ;
62
65
private static final int DEFAULT_REQUEST_TIMEOUT_MILLIS = 10000 ;
63
66
67
+ private Counter requestStatusErrorCounter ;
68
+ private Counter requestStatusSuccessCounter ;
69
+ private static final String SERVICE_REQUESTS_STATUS_COUNTER =
70
+ "hypertrace.gateway.service.requests.status" ;
71
+
64
72
private final TracesService traceService ;
65
73
private final SpanService spanService ;
66
74
private final EntityService entityService ;
@@ -134,6 +142,16 @@ public GatewayServiceImpl(Config appConfig) {
134
142
entityIdColumnsConfigs );
135
143
this .logEventsService =
136
144
new LogEventsService (queryServiceClient , qsRequestTimeout , attributeMetadataProvider );
145
+ initMetrics ();
146
+ }
147
+
148
+ private void initMetrics () {
149
+ requestStatusErrorCounter =
150
+ PlatformMetricsRegistry .registerCounter (
151
+ SERVICE_REQUESTS_STATUS_COUNTER , ImmutableMap .of ("error" , "true" ));
152
+ requestStatusSuccessCounter =
153
+ PlatformMetricsRegistry .registerCounter (
154
+ SERVICE_REQUESTS_STATUS_COUNTER , ImmutableMap .of ("error" , "false" ));
137
155
}
138
156
139
157
private static int getRequestTimeoutMillis (Config config ) {
@@ -152,6 +170,7 @@ public void getTraces(
152
170
Optional <String > tenantId =
153
171
org .hypertrace .core .grpcutils .context .RequestContext .CURRENT .get ().getTenantId ();
154
172
if (tenantId .isEmpty ()) {
173
+ requestStatusErrorCounter .increment ();
155
174
responseObserver .onError (new ServiceException ("Tenant id is missing in the request." ));
156
175
return ;
157
176
}
@@ -167,8 +186,10 @@ public void getTraces(
167
186
TracesResponse response = traceService .getTracesByFilter (requestContext , request );
168
187
responseObserver .onNext (response );
169
188
responseObserver .onCompleted ();
189
+ requestStatusSuccessCounter .increment ();
170
190
} catch (Exception e ) {
171
191
LOG .error ("Error while handling traces request: {}" , request , e );
192
+ requestStatusErrorCounter .increment ();
172
193
responseObserver .onError (e );
173
194
}
174
195
}
@@ -181,6 +202,7 @@ public void getSpans(
181
202
Optional <String > tenantId =
182
203
org .hypertrace .core .grpcutils .context .RequestContext .CURRENT .get ().getTenantId ();
183
204
if (tenantId .isEmpty ()) {
205
+ requestStatusErrorCounter .increment ();
184
206
responseObserver .onError (new ServiceException ("Tenant id is missing in the request." ));
185
207
return ;
186
208
}
@@ -195,8 +217,10 @@ public void getSpans(
195
217
SpansResponse response = spanService .getSpansByFilter (context , request );
196
218
responseObserver .onNext (response );
197
219
responseObserver .onCompleted ();
220
+ requestStatusSuccessCounter .increment ();
198
221
} catch (Exception e ) {
199
222
LOG .error ("Error while handling spans request: {}" , request , e );
223
+ requestStatusErrorCounter .increment ();
200
224
responseObserver .onError (e );
201
225
}
202
226
}
@@ -211,6 +235,7 @@ public void getEntities(
211
235
Optional <String > tenantId =
212
236
org .hypertrace .core .grpcutils .context .RequestContext .CURRENT .get ().getTenantId ();
213
237
if (tenantId .isEmpty ()) {
238
+ requestStatusErrorCounter .increment ();
214
239
responseObserver .onError (new ServiceException ("Tenant id is missing in the request." ));
215
240
return ;
216
241
}
@@ -241,8 +266,10 @@ public void getEntities(
241
266
242
267
responseObserver .onNext (response );
243
268
responseObserver .onCompleted ();
269
+ requestStatusSuccessCounter .increment ();
244
270
} catch (Exception e ) {
245
271
LOG .error ("Error while handling entities request: {}." , request , e );
272
+ requestStatusErrorCounter .increment ();
246
273
responseObserver .onError (e );
247
274
}
248
275
}
@@ -257,6 +284,7 @@ public void updateEntity(
257
284
Optional <String > tenantId =
258
285
org .hypertrace .core .grpcutils .context .RequestContext .CURRENT .get ().getTenantId ();
259
286
if (tenantId .isEmpty ()) {
287
+ requestStatusErrorCounter .increment ();
260
288
responseObserver .onError (new ServiceException ("Tenant id is missing in the request." ));
261
289
return ;
262
290
}
@@ -275,8 +303,10 @@ public void updateEntity(
275
303
}
276
304
responseObserver .onNext (response );
277
305
responseObserver .onCompleted ();
306
+ requestStatusSuccessCounter .increment ();
278
307
} catch (Exception e ) {
279
308
LOG .error ("Error while handling UpdateEntityRequest: {}." , request , e );
309
+ requestStatusErrorCounter .increment ();
280
310
responseObserver .onError (e );
281
311
}
282
312
}
@@ -305,8 +335,10 @@ public void bulkUpdateEntities(
305
335
LOG .debug ("Received response: {}" , response );
306
336
responseObserver .onNext (response );
307
337
responseObserver .onCompleted ();
338
+ requestStatusSuccessCounter .increment ();
308
339
} catch (Exception e ) {
309
340
LOG .error ("Error while handling bulkUpdateEntities: {}." , request , e );
341
+ requestStatusErrorCounter .increment ();
310
342
responseObserver .onError (e );
311
343
}
312
344
}
@@ -317,6 +349,7 @@ public void getBaselineForEntities(
317
349
Optional <String > tenantId =
318
350
org .hypertrace .core .grpcutils .context .RequestContext .CURRENT .get ().getTenantId ();
319
351
if (tenantId .isEmpty ()) {
352
+ requestStatusErrorCounter .increment ();
320
353
responseObserver .onError (new ServiceException ("Tenant id is missing in the request." ));
321
354
return ;
322
355
}
@@ -334,8 +367,10 @@ public void getBaselineForEntities(
334
367
335
368
responseObserver .onNext (response );
336
369
responseObserver .onCompleted ();
370
+ requestStatusSuccessCounter .increment ();
337
371
} catch (Exception e ) {
338
372
LOG .error ("Error while handling entities request: {}." , request , e );
373
+ requestStatusErrorCounter .increment ();
339
374
responseObserver .onError (e );
340
375
}
341
376
}
@@ -345,6 +380,7 @@ public void explore(ExploreRequest request, StreamObserver<ExploreResponse> resp
345
380
Optional <String > tenantId =
346
381
org .hypertrace .core .grpcutils .context .RequestContext .CURRENT .get ().getTenantId ();
347
382
if (tenantId .isEmpty ()) {
383
+ requestStatusErrorCounter .increment ();
348
384
responseObserver .onError (new ServiceException ("Tenant id is missing in the request." ));
349
385
return ;
350
386
}
@@ -359,8 +395,10 @@ public void explore(ExploreRequest request, StreamObserver<ExploreResponse> resp
359
395
.getRequestHeaders ());
360
396
responseObserver .onNext (response );
361
397
responseObserver .onCompleted ();
398
+ requestStatusSuccessCounter .increment ();
362
399
} catch (Exception e ) {
363
400
LOG .error ("Error while handling explore request: {}" , request , e );
401
+ requestStatusErrorCounter .increment ();
364
402
responseObserver .onError (e );
365
403
}
366
404
}
@@ -371,6 +409,7 @@ public void getLogEvents(
371
409
Optional <String > tenantId =
372
410
org .hypertrace .core .grpcutils .context .RequestContext .CURRENT .get ().getTenantId ();
373
411
if (tenantId .isEmpty ()) {
412
+ requestStatusErrorCounter .increment ();
374
413
responseObserver .onError (new ServiceException ("Tenant id is missing in the request." ));
375
414
return ;
376
415
}
@@ -385,8 +424,10 @@ public void getLogEvents(
385
424
LogEventsResponse response = logEventsService .getLogEventsByFilter (context , request );
386
425
responseObserver .onNext (response );
387
426
responseObserver .onCompleted ();
427
+ requestStatusSuccessCounter .increment ();
388
428
} catch (Exception e ) {
389
429
LOG .error ("Error while handling logEvents request: {}" , request , e );
430
+ requestStatusErrorCounter .increment ();
390
431
responseObserver .onError (e );
391
432
}
392
433
}
0 commit comments