logbroker.proto 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. syntax = "proto3";
  2. package docker.swarmkit.v1;
  3. import "gogoproto/gogo.proto";
  4. import "google/protobuf/timestamp.proto";
  5. import "plugin/plugin.proto";
  6. // LogStream defines the stream from which the log message came.
  7. enum LogStream {
  8. option (gogoproto.goproto_enum_prefix) = false;
  9. option (gogoproto.enum_customname) = "LogStream";
  10. LOG_STREAM_UNKNOWN = 0 [(gogoproto.enumvalue_customname) = "LogStreamUnknown"];
  11. LOG_STREAM_STDOUT = 1 [(gogoproto.enumvalue_customname) = "LogStreamStdout"];
  12. LOG_STREAM_STDERR = 2 [(gogoproto.enumvalue_customname) = "LogStreamStderr"];
  13. }
  14. message LogSubscriptionOptions {
  15. // Streams defines which log streams should be sent from the task source.
  16. // Empty means send all the messages.
  17. repeated LogStream streams = 1;
  18. // Follow instructs the publisher to continue sending log messages as they
  19. // are produced, after satisfying the initial query.
  20. bool follow = 2;
  21. // Tail defines how many messages relative to the log stream to send when
  22. // starting the stream.
  23. //
  24. // Positive values will skip that number of messages from the start of the
  25. // stream before publishing.
  26. //
  27. // Negative values will specify messages relative to the end of the stream,
  28. // offset by one. We can say that the last (-n-1) lines are returned when n
  29. // < 0. As reference, -1 would mean send no log lines (typically used with
  30. // follow), -2 would return the last log line, -11 would return the last 10
  31. // and so on.
  32. //
  33. // The default value of zero will return all logs.
  34. //
  35. // Note that this is very different from the Docker API.
  36. int64 tail = 3;
  37. // Since indicates that only log messages produced after this timestamp
  38. // should be sent.
  39. // Note: can't use stdtime because this field is nullable.
  40. google.protobuf.Timestamp since = 4;
  41. }
  42. // LogSelector will match logs from ANY of the defined parameters.
  43. //
  44. // For the best effect, the client should use the least specific parameter
  45. // possible. For example, if they want to listen to all the tasks of a service,
  46. // they should use the service id, rather than specifying the individual tasks.
  47. message LogSelector {
  48. repeated string service_ids = 1;
  49. repeated string node_ids = 2;
  50. repeated string task_ids = 3;
  51. }
  52. // LogContext marks the context from which a log message was generated.
  53. message LogContext {
  54. string service_id = 1;
  55. string node_id = 2;
  56. string task_id = 3;
  57. }
  58. // LogMessage
  59. message LogMessage {
  60. // Context identifies the source of the log message.
  61. LogContext context = 1 [(gogoproto.nullable) = false];
  62. // Timestamp is the time at which the message was generated.
  63. // Note: can't use stdtime because this field is nullable.
  64. google.protobuf.Timestamp timestamp = 2;
  65. // Stream identifies the stream of the log message, stdout or stderr.
  66. LogStream stream = 3;
  67. // Data is the raw log message, as generated by the application.
  68. bytes data = 4;
  69. }
  70. // Logs defines the methods for retrieving task logs messages from a cluster.
  71. service Logs {
  72. // SubscribeLogs starts a subscription with the specified selector and options.
  73. //
  74. // The subscription will be distributed to relevant nodes and messages will
  75. // be collected and sent via the returned stream.
  76. //
  77. // The subscription will end with an EOF.
  78. rpc SubscribeLogs(SubscribeLogsRequest) returns (stream SubscribeLogsMessage) {
  79. option (docker.protobuf.plugin.tls_authorization) = { roles: "swarm-manager" };
  80. }
  81. }
  82. message SubscribeLogsRequest {
  83. // LogSelector describes the logs to which the subscriber is
  84. LogSelector selector = 1;
  85. LogSubscriptionOptions options = 2;
  86. }
  87. message SubscribeLogsMessage {
  88. repeated LogMessage messages = 1 [(gogoproto.nullable) = false];
  89. }
  90. // LogBroker defines the API used by the worker to send task logs back to a
  91. // manager. A client listens for subscriptions then optimistically retrieves
  92. // logs satisfying said subscriptions, calling PublishLogs for results that are
  93. // relevant.
  94. //
  95. // The structure of ListenSubscriptions is similar to the Dispatcher API but
  96. // decoupled to allow log distribution to work outside of the regular task
  97. // flow.
  98. service LogBroker {
  99. // ListenSubscriptions starts a subscription stream for the node. For each
  100. // message received, the node should attempt to satisfy the subscription.
  101. //
  102. // Log messages that match the provided subscription should be sent via
  103. // PublishLogs.
  104. rpc ListenSubscriptions(ListenSubscriptionsRequest) returns (stream SubscriptionMessage) {
  105. option (docker.protobuf.plugin.tls_authorization) = {
  106. roles: "swarm-worker"
  107. roles: "swarm-manager"
  108. };
  109. }
  110. // PublishLogs receives sets of log messages destined for a single
  111. // subscription identifier.
  112. rpc PublishLogs(stream PublishLogsMessage) returns (PublishLogsResponse) {
  113. option (docker.protobuf.plugin.tls_authorization) = {
  114. roles: "swarm-worker"
  115. roles: "swarm-manager"
  116. };
  117. }
  118. }
  119. // ListenSubscriptionsRequest is a placeholder to begin listening for
  120. // subscriptions.
  121. message ListenSubscriptionsRequest { }
  122. // SubscriptionMessage instructs the listener to start publishing messages for
  123. // the stream or end a subscription.
  124. //
  125. // If Options.Follow == false, the worker should end the subscription on its own.
  126. message SubscriptionMessage {
  127. // ID identifies the subscription.
  128. string id = 1;
  129. // Selector defines which sources should be sent for the subscription.
  130. LogSelector selector = 2;
  131. // Options specify how the subscription should be satisfied.
  132. LogSubscriptionOptions options = 3;
  133. // Close will be true if the node should shutdown the subscription with the
  134. // provided identifier.
  135. bool close = 4;
  136. }
  137. message PublishLogsMessage {
  138. // SubscriptionID identifies which subscription the set of messages should
  139. // be sent to. We can think of this as a "mail box" for the subscription.
  140. string subscription_id = 1;
  141. // Messages is the log message for publishing.
  142. repeated LogMessage messages = 2 [(gogoproto.nullable) = false];
  143. }
  144. message PublishLogsResponse { }