blob: 6cbe32b234a69a56e00ad6f3d0d1446a1d8627dc [file] [log] [blame]
Serge Bazanskiefdb6e92020-07-13 17:19:27 +02001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
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
17syntax = "proto3";
Serge Bazanski662b5b32020-12-21 13:49:00 +010018package metropolis.proto.api;
Serge Bazanski31370b02021-01-07 16:31:14 +010019option go_package = "source.monogon.dev/metropolis/proto/api";
Serge Bazanskiefdb6e92020-07-13 17:19:27 +020020
Serge Bazanski662b5b32020-12-21 13:49:00 +010021// NodeDebugService exposes debug and testing endpoints that allow introspection into a running Metropolis node.
Serge Bazanski77cb6c52020-12-19 00:09:22 +010022// It is not authenticated and will be disabled in production. It is currently consumed by metropolis/cli/dbg and
23// by tests.
Serge Bazanskiefdb6e92020-07-13 17:19:27 +020024service NodeDebugService {
25 // GetDebugKubeconfig issues kubeconfigs with arbitrary identities and groups for debugging
26 rpc GetDebugKubeconfig(GetDebugKubeconfigRequest) returns (GetDebugKubeconfigResponse);
Serge Bazanskib0272182020-11-02 18:39:44 +010027
28 // GetLogs Returns historical and/or streaming logs for a given DN with given filters from the system global
29 // LogTree.
30 //
Serge Bazanski549b72b2021-01-07 14:54:19 +010031 // For more information about this API, see //metropolis/pkg/logtree. But, in summary:
Serge Bazanskib0272182020-11-02 18:39:44 +010032 // - All logging is performed to a DN (distinguished name), which is a dot-delimited string like foo.bar.baz.
33 // - Log entries can be either raw (coming from unstructured logging from an external service, like a running
Serge Bazanski662b5b32020-12-21 13:49:00 +010034 // process) or leveled (emitted by Metropolis code with a source line, timestamp, and severity).
Serge Bazanskib0272182020-11-02 18:39:44 +010035 // - The DNs form a tree of logging nodes - and when requesting logs, a given subtree of DNs can be requested,
36 // instead of just a given DN.
37 // - All supervised processes live at `root.<supervisor DN>`. For more example paths, see the console logs of
Serge Bazanski662b5b32020-12-21 13:49:00 +010038 // a running Metropolis node, or request all logs (at DN "").
Serge Bazanskib0272182020-11-02 18:39:44 +010039 //
40 // TODO(q3k): move method and its related messages to the non-debug node endpoint once we have one.
41 rpc GetLogs(GetLogsRequest) returns (stream GetLogsResponse);
Lorenz Brun09c275b2021-03-30 12:47:09 +020042
43 // Trace enables tracing of Metropolis using the Linux ftrace infrastructure.
44 rpc Trace(TraceRequest) returns (stream TraceEvent);
Serge Bazanskiefdb6e92020-07-13 17:19:27 +020045}
46
47
48message GetDebugKubeconfigRequest {
49 string id = 1; // Kubernetes identity (user)
50 repeated string groups = 2; // Kubernetes groups
51}
52
53message GetDebugKubeconfigResponse {
54 string debug_kubeconfig = 1;
55}
56
Serge Bazanski549b72b2021-01-07 14:54:19 +010057// Severity level corresponding to //metropolis/pkg/logtree.Severity.
Serge Bazanskib0272182020-11-02 18:39:44 +010058enum LeveledLogSeverity {
59 INVALID = 0;
60 INFO = 1;
61 WARNING = 2;
62 ERROR = 3;
63 FATAL = 4;
Serge Bazanskiefdb6e92020-07-13 17:19:27 +020064}
65
Serge Bazanskib0272182020-11-02 18:39:44 +010066// Filter set when requesting logs for a given DN. This message is equivalent to the following GADT enum:
67// data LogFilter = WithChildren
68// | OnlyRaw
69// | OnlyLeveled
70// | LeveledWithMinimumSeverity(Severity)
71//
72// Multiple LogFilters can be chained/combined when requesting logs, as long as they do not conflict.
73message LogFilter {
74 // Entries will be returned not only for the given DN, but all child DNs as well. For instance, if the
75 // requested DN is foo, entries logged to foo, foo.bar and foo.bar.baz will all be returned.
76 message WithChildren {
77 }
78 // Only raw logging entries will be returned. Conflicts with OnlyLeveled filters.
79 message OnlyRaw {
80 }
81 // Only leveled logging entries will be returned. Conflicts with OnlyRaw filters.
82 message OnlyLeveled {
83 }
84 // If leveled logs are returned, all entries at severity lower than `minimum` will be discarded.
85 message LeveledWithMinimumSeverity {
86 LeveledLogSeverity minimum = 1;
87 }
88 oneof filter {
89 WithChildren with_children = 1;
90 OnlyRaw only_raw = 3;
91 OnlyLeveled only_leveled = 4;
92 LeveledWithMinimumSeverity leveled_with_minimum_severity = 5;
93 }
94}
95
96message GetLogsRequest {
97 // DN from which to request logs. All supervised runnables live at `root.`, the init code lives at `init.`.
98 string dn = 1;
99 // Filters to apply to returned data.
100 repeated LogFilter filters = 2;
101
102 enum BacklogMode {
103 BACKLOG_INVALID = 0;
104 // No historic data will be returned.
105 BACKLOG_DISABLE = 1;
106 // All available historic data will be returned.
107 BACKLOG_ALL = 2;
108 // At most backlog_count entries will be returned, if available.
109 BACKLOG_COUNT = 3;
110 }
111 BacklogMode backlog_mode = 3;
112 int64 backlog_count = 4;
113
114 enum StreamMode {
115 STREAM_INVALID = 0;
116 // No streaming entries, gRPC stream will be closed as soon as all backlog data is served.
117 STREAM_DISABLE = 1;
118 // Entries will be streamed as early as available right after all backlog data is served.
119 STREAM_UNBUFFERED = 2;
120 }
121 StreamMode stream_mode = 5;
122}
123
124message GetLogsResponse {
125 // Entries from the requested historical entries (via WithBackLog). They will all be served before the first
126 // stream_entries are served (if any).
127 repeated LogEntry backlog_entries = 1;
128 // Entries streamed as they arrive. Currently no server-side buffering is enabled, instead every line is served
129 // as early as it arrives. However, this might change in the future, so this behaviour cannot be depended
130 // upon.
131 repeated LogEntry stream_entries = 2;
132}
133
134message LogEntry {
135 message Leveled {
Serge Bazanski12971d62020-11-17 12:12:58 +0100136 repeated string lines = 1;
Serge Bazanskib0272182020-11-02 18:39:44 +0100137 int64 timestamp = 2;
138 LeveledLogSeverity severity = 3;
139 string location = 4;
140 }
141 message Raw {
142 string data = 1;
143 int64 original_length = 2;
144 }
145
146 string dn = 1;
147 oneof kind {
148 Leveled leveled = 2;
149 Raw raw = 3;
150 }
Serge Bazanskiefdb6e92020-07-13 17:19:27 +0200151}
Lorenz Brun09c275b2021-03-30 12:47:09 +0200152
153message TraceRequest {
154 // Name of the tracer to use. Defined in https://www.kernel.org/doc/html/latest/trace/ftrace.html#the-tracers.
155 // Useful ones enabled in Metropolis: function_graph, function.
156 // Gets reset to nop automatically after the stream is terminated.
157 string tracer = 1;
158
159 // List of functions to trace. Accepts wildcards using the '*' character. If left empty traces all functions.
160 repeated string function_filter = 2;
161
162 // List of functions and their descendants to trace with the function_graph tracer.
163 repeated string graph_function_filter = 3;
164}
165
166message TraceEvent {
167 // Currently we do not parse the event data and just return what the kernel outputs, line-by-line.
168 string raw_line = 1;
169}