@gitpod/ide-metrics-api-grpcweb 0.0.1-pd-ide-metrics-http.5 → 0.0.1-se-better-ts-api.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,101 @@
1
+ // package: ide_metrics_api
2
+ // file: idemetrics.proto
3
+
4
+ import * as idemetrics_pb from "./idemetrics_pb";
5
+ import {grpc} from "@improbable-eng/grpc-web";
6
+
7
+ type MetricsServiceAddCounter = {
8
+ readonly methodName: string;
9
+ readonly service: typeof MetricsService;
10
+ readonly requestStream: false;
11
+ readonly responseStream: false;
12
+ readonly requestType: typeof idemetrics_pb.AddCounterRequest;
13
+ readonly responseType: typeof idemetrics_pb.AddCounterResponse;
14
+ };
15
+
16
+ type MetricsServiceObserveHistogram = {
17
+ readonly methodName: string;
18
+ readonly service: typeof MetricsService;
19
+ readonly requestStream: false;
20
+ readonly responseStream: false;
21
+ readonly requestType: typeof idemetrics_pb.ObserveHistogramRequest;
22
+ readonly responseType: typeof idemetrics_pb.ObserveHistogramResponse;
23
+ };
24
+
25
+ type MetricsServicereportError = {
26
+ readonly methodName: string;
27
+ readonly service: typeof MetricsService;
28
+ readonly requestStream: false;
29
+ readonly responseStream: false;
30
+ readonly requestType: typeof idemetrics_pb.ReportErrorRequest;
31
+ readonly responseType: typeof idemetrics_pb.ReportErrorResponse;
32
+ };
33
+
34
+ export class MetricsService {
35
+ static readonly serviceName: string;
36
+ static readonly AddCounter: MetricsServiceAddCounter;
37
+ static readonly ObserveHistogram: MetricsServiceObserveHistogram;
38
+ static readonly reportError: MetricsServicereportError;
39
+ }
40
+
41
+ export type ServiceError = { message: string, code: number; metadata: grpc.Metadata }
42
+ export type Status = { details: string, code: number; metadata: grpc.Metadata }
43
+
44
+ interface UnaryResponse {
45
+ cancel(): void;
46
+ }
47
+ interface ResponseStream<T> {
48
+ cancel(): void;
49
+ on(type: 'data', handler: (message: T) => void): ResponseStream<T>;
50
+ on(type: 'end', handler: (status?: Status) => void): ResponseStream<T>;
51
+ on(type: 'status', handler: (status: Status) => void): ResponseStream<T>;
52
+ }
53
+ interface RequestStream<T> {
54
+ write(message: T): RequestStream<T>;
55
+ end(): void;
56
+ cancel(): void;
57
+ on(type: 'end', handler: (status?: Status) => void): RequestStream<T>;
58
+ on(type: 'status', handler: (status: Status) => void): RequestStream<T>;
59
+ }
60
+ interface BidirectionalStream<ReqT, ResT> {
61
+ write(message: ReqT): BidirectionalStream<ReqT, ResT>;
62
+ end(): void;
63
+ cancel(): void;
64
+ on(type: 'data', handler: (message: ResT) => void): BidirectionalStream<ReqT, ResT>;
65
+ on(type: 'end', handler: (status?: Status) => void): BidirectionalStream<ReqT, ResT>;
66
+ on(type: 'status', handler: (status: Status) => void): BidirectionalStream<ReqT, ResT>;
67
+ }
68
+
69
+ export class MetricsServiceClient {
70
+ readonly serviceHost: string;
71
+
72
+ constructor(serviceHost: string, options?: grpc.RpcOptions);
73
+ addCounter(
74
+ requestMessage: idemetrics_pb.AddCounterRequest,
75
+ metadata: grpc.Metadata,
76
+ callback: (error: ServiceError|null, responseMessage: idemetrics_pb.AddCounterResponse|null) => void
77
+ ): UnaryResponse;
78
+ addCounter(
79
+ requestMessage: idemetrics_pb.AddCounterRequest,
80
+ callback: (error: ServiceError|null, responseMessage: idemetrics_pb.AddCounterResponse|null) => void
81
+ ): UnaryResponse;
82
+ observeHistogram(
83
+ requestMessage: idemetrics_pb.ObserveHistogramRequest,
84
+ metadata: grpc.Metadata,
85
+ callback: (error: ServiceError|null, responseMessage: idemetrics_pb.ObserveHistogramResponse|null) => void
86
+ ): UnaryResponse;
87
+ observeHistogram(
88
+ requestMessage: idemetrics_pb.ObserveHistogramRequest,
89
+ callback: (error: ServiceError|null, responseMessage: idemetrics_pb.ObserveHistogramResponse|null) => void
90
+ ): UnaryResponse;
91
+ reportError(
92
+ requestMessage: idemetrics_pb.ReportErrorRequest,
93
+ metadata: grpc.Metadata,
94
+ callback: (error: ServiceError|null, responseMessage: idemetrics_pb.ReportErrorResponse|null) => void
95
+ ): UnaryResponse;
96
+ reportError(
97
+ requestMessage: idemetrics_pb.ReportErrorRequest,
98
+ callback: (error: ServiceError|null, responseMessage: idemetrics_pb.ReportErrorResponse|null) => void
99
+ ): UnaryResponse;
100
+ }
101
+
@@ -0,0 +1,141 @@
1
+ // package: ide_metrics_api
2
+ // file: idemetrics.proto
3
+
4
+ var idemetrics_pb = require("./idemetrics_pb");
5
+ var grpc = require("@improbable-eng/grpc-web").grpc;
6
+
7
+ var MetricsService = (function () {
8
+ function MetricsService() {}
9
+ MetricsService.serviceName = "ide_metrics_api.MetricsService";
10
+ return MetricsService;
11
+ }());
12
+
13
+ MetricsService.AddCounter = {
14
+ methodName: "AddCounter",
15
+ service: MetricsService,
16
+ requestStream: false,
17
+ responseStream: false,
18
+ requestType: idemetrics_pb.AddCounterRequest,
19
+ responseType: idemetrics_pb.AddCounterResponse
20
+ };
21
+
22
+ MetricsService.ObserveHistogram = {
23
+ methodName: "ObserveHistogram",
24
+ service: MetricsService,
25
+ requestStream: false,
26
+ responseStream: false,
27
+ requestType: idemetrics_pb.ObserveHistogramRequest,
28
+ responseType: idemetrics_pb.ObserveHistogramResponse
29
+ };
30
+
31
+ MetricsService.reportError = {
32
+ methodName: "reportError",
33
+ service: MetricsService,
34
+ requestStream: false,
35
+ responseStream: false,
36
+ requestType: idemetrics_pb.ReportErrorRequest,
37
+ responseType: idemetrics_pb.ReportErrorResponse
38
+ };
39
+
40
+ exports.MetricsService = MetricsService;
41
+
42
+ function MetricsServiceClient(serviceHost, options) {
43
+ this.serviceHost = serviceHost;
44
+ this.options = options || {};
45
+ }
46
+
47
+ MetricsServiceClient.prototype.addCounter = function addCounter(requestMessage, metadata, callback) {
48
+ if (arguments.length === 2) {
49
+ callback = arguments[1];
50
+ }
51
+ var client = grpc.unary(MetricsService.AddCounter, {
52
+ request: requestMessage,
53
+ host: this.serviceHost,
54
+ metadata: metadata,
55
+ transport: this.options.transport,
56
+ debug: this.options.debug,
57
+ onEnd: function (response) {
58
+ if (callback) {
59
+ if (response.status !== grpc.Code.OK) {
60
+ var err = new Error(response.statusMessage);
61
+ err.code = response.status;
62
+ err.metadata = response.trailers;
63
+ callback(err, null);
64
+ } else {
65
+ callback(null, response.message);
66
+ }
67
+ }
68
+ }
69
+ });
70
+ return {
71
+ cancel: function () {
72
+ callback = null;
73
+ client.close();
74
+ }
75
+ };
76
+ };
77
+
78
+ MetricsServiceClient.prototype.observeHistogram = function observeHistogram(requestMessage, metadata, callback) {
79
+ if (arguments.length === 2) {
80
+ callback = arguments[1];
81
+ }
82
+ var client = grpc.unary(MetricsService.ObserveHistogram, {
83
+ request: requestMessage,
84
+ host: this.serviceHost,
85
+ metadata: metadata,
86
+ transport: this.options.transport,
87
+ debug: this.options.debug,
88
+ onEnd: function (response) {
89
+ if (callback) {
90
+ if (response.status !== grpc.Code.OK) {
91
+ var err = new Error(response.statusMessage);
92
+ err.code = response.status;
93
+ err.metadata = response.trailers;
94
+ callback(err, null);
95
+ } else {
96
+ callback(null, response.message);
97
+ }
98
+ }
99
+ }
100
+ });
101
+ return {
102
+ cancel: function () {
103
+ callback = null;
104
+ client.close();
105
+ }
106
+ };
107
+ };
108
+
109
+ MetricsServiceClient.prototype.reportError = function reportError(requestMessage, metadata, callback) {
110
+ if (arguments.length === 2) {
111
+ callback = arguments[1];
112
+ }
113
+ var client = grpc.unary(MetricsService.reportError, {
114
+ request: requestMessage,
115
+ host: this.serviceHost,
116
+ metadata: metadata,
117
+ transport: this.options.transport,
118
+ debug: this.options.debug,
119
+ onEnd: function (response) {
120
+ if (callback) {
121
+ if (response.status !== grpc.Code.OK) {
122
+ var err = new Error(response.statusMessage);
123
+ err.code = response.status;
124
+ err.metadata = response.trailers;
125
+ callback(err, null);
126
+ } else {
127
+ callback(null, response.message);
128
+ }
129
+ }
130
+ }
131
+ });
132
+ return {
133
+ cancel: function () {
134
+ callback = null;
135
+ client.close();
136
+ }
137
+ };
138
+ };
139
+
140
+ exports.MetricsServiceClient = MetricsServiceClient;
141
+
package/lib/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
+ * Licensed under the GNU Affero General Public License (AGPL).
4
+ * See License-AGPL.txt in the project root for license information.
5
+ */
6
+ export * from "../lib/idemetrics_pb";
7
+ export * from "../lib/idemetrics_pb_service";
8
+ import { MetricsServiceClient } from "../lib/idemetrics_pb_service";
9
+ export interface IDEMetric {
10
+ kind: "counter" | "histogram";
11
+ name: string;
12
+ labels: Record<string, string>;
13
+ value?: number;
14
+ }
15
+ export declare function sendMetrics(client: MetricsServiceClient, metrics: IDEMetric[]): Promise<PromiseSettledResult<void>[]>;