Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: web/inc/logdog-stream/client.ts

Issue 2717043002: Add LogDog log stream fetcher code. (Closed)
Patch Set: fix bug, underscore variable names Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file.
5 */
6
7 ///<reference path="logdog.ts" />
8 ///<reference path="../rpc/client.ts" />
9
10 namespace LogDog {
11
12 export type GetRequest = {
13 project: string; path: string; state: boolean; index: number;
14
15 nonContiguous?: boolean;
16 byteCount?: number;
17 logCount?: number;
18 };
19
20 export type TailRequest = {project: string; path: string; state: boolean;};
21
22 // Type of a "Get" or "Tail" response (protobuf).
23 export type GetResponse = {state: any; desc: any; logs: any[];};
24
25 /** Configurable set of log stream query parameters. */
26 export type QueryRequest = {
27 project: string; getMeta?: boolean; path?: string; contentType?: string;
28 streamType?: LogDog.StreamType;
29 purged?: boolean;
30 newer?: Date;
31 older?: Date;
32 protoVersion?: string;
33 tags?: {[key: string]: string};
34 };
35
36 /** The result of a log stream query. */
37 export type QueryResult = {
38 stream: LogDog.StreamPath; state?: LogDog.LogStreamState;
39 desc?: LogDog.LogStreamDescriptor;
40 };
41
42 export class Client {
43 debug = false;
44
45 constructor(private client: luci.Client) {}
46
47 /** Get executes a Get RPC. */
48 get(req: GetRequest): Promise<GetResponse> {
49 if (this.debug) {
50 console.log('logdog.Logs.Get:', req);
51 }
52 return this.client.call('logdog.Logs', 'Get', req);
53 }
54
55 /** Tail executes a Tail RPC. */
56 tail(stream: StreamPath, state: boolean): Promise<GetResponse> {
57 let request: TailRequest = {
58 project: stream.project,
59 path: stream.path,
60 state: state,
61 };
62
63 if (this.debug) {
64 console.log('logdog.Logs.Tail:', request);
65 }
66 return this.client.call('logdog.Logs', 'Tail', request);
67 }
68
69 /**
70 * Query executes a Query RPC.
71 *
72 * @param params The query request parameters.
73 * @param cursor The cursor to supply. Can be empty for no cursor.
74 * @param limit The maximum number of query results to return.
75 *
76 * @return a Promise that resolves to the query results and continuation
77 * cursor. The cursor may be empty if the query finished.
78 */
79 query(params: QueryRequest, cursor = '', limit = 0):
80 Promise<[QueryResult[], string]> {
81 let project = params.project;
82 let body: any = {
83 project: project,
84 path: params.path,
85 content_type: params.contentType,
86 proto_version: params.protoVersion,
87 tags: params.tags,
88
89 next: cursor,
90 max_results: limit,
91 };
92
93 let trinary = (v: boolean): string => {
94 return ((v) ? 'YES' : 'NO');
95 };
96 if (params.purged != null) {
97 body.purged = trinary(params.purged);
98 }
99
100 if (params.streamType !== undefined) {
101 body.stream_type = {value: LogDog.StreamType[params.streamType]};
102 }
103 if (params.newer) {
104 body.newer = params.newer.toISOString();
105 }
106 if (params.older) {
107 body.older = params.older.toISOString();
108 }
109
110 type responseType = {
111 streams: {
112 path: string,
113 state: any,
114 desc: any,
115 }[];
116 next: string;
117 };
118
119 return this.client.call('logdog.Logs', 'Query', body)
120 .then((resp: responseType): [QueryResult[], string] => {
121
122 // Package the response in QueryResults.
123 let results = (resp.streams || []).map(entry => {
124 let res: QueryResult = {
125 stream: new LogDog.StreamPath(project, entry.path),
126 };
127 if (entry.state) {
128 res.state = LogDog.LogStreamState.make(entry.state);
129 }
130 if (entry.desc) {
131 res.desc = LogDog.LogStreamDescriptor.make(entry.desc);
132 }
133 return res;
134 });
135 return [results, resp.next];
136 });
137 }
138 }
139 }
OLDNEW
« no previous file with comments | « web/inc/logdog-stream-view/logdog-stream-fetcher.html ('k') | web/inc/luci-operation/operation.ts » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698