feat: add event actor id to client api and events cmd
Add the missing actor id on the event and a way to filter by it to the events cli command. Related to siderolabs/talos#5499. Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
This commit is contained in:
parent
9baca49662
commit
586e29dfca
@ -25,6 +25,7 @@ var eventsCmdFlags struct {
|
||||
tailEvents int32
|
||||
tailDuration time.Duration
|
||||
tailID string
|
||||
actorID string
|
||||
}
|
||||
|
||||
// eventsCmd represents the events command.
|
||||
@ -35,7 +36,7 @@ var eventsCmd = &cobra.Command{
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return WithClient(func(ctx context.Context, c *client.Client) error {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
|
||||
fmt.Fprintln(w, "NODE\tID\tEVENT\tSOURCE\tMESSAGE")
|
||||
fmt.Fprintln(w, "NODE\tID\tEVENT\tACTOR\tSOURCE\tMESSAGE")
|
||||
|
||||
opts := []client.EventsOptionFunc{}
|
||||
|
||||
@ -51,13 +52,17 @@ var eventsCmd = &cobra.Command{
|
||||
opts = append(opts, client.WithTailID(eventsCmdFlags.tailID))
|
||||
}
|
||||
|
||||
if eventsCmdFlags.actorID != "" {
|
||||
opts = append(opts, client.WithActorID(eventsCmdFlags.actorID))
|
||||
}
|
||||
|
||||
events, err := c.Events(ctx, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return helpers.ReadGRPCStream(events, func(ev *machine.Event, node string, multipleNodes bool) error {
|
||||
format := "%s\t%s\t%s\t%s\t%s\n"
|
||||
format := "%s\t%s\t%s\n%s\t%s\t%s\n"
|
||||
|
||||
event, err := client.UnmarshalEvent(ev)
|
||||
if err != nil {
|
||||
@ -104,7 +109,7 @@ var eventsCmd = &cobra.Command{
|
||||
}
|
||||
}
|
||||
|
||||
args = append([]interface{}{event.Node, event.ID, event.TypeURL}, args...)
|
||||
args = append([]interface{}{event.Node, event.ID, event.TypeURL, event.ActorID}, args...)
|
||||
fmt.Fprintf(w, format, args...)
|
||||
|
||||
return w.Flush()
|
||||
@ -118,4 +123,5 @@ func init() {
|
||||
eventsCmd.Flags().Int32Var(&eventsCmdFlags.tailEvents, "tail", 0, "show specified number of past events (use -1 to show full history, default is to show no history)")
|
||||
eventsCmd.Flags().DurationVar(&eventsCmdFlags.tailDuration, "duration", 0, "show events for the past duration interval (one second resolution, default is to show no history)")
|
||||
eventsCmd.Flags().StringVar(&eventsCmdFlags.tailID, "since", "", "show events after the specified event ID (default is to show no history)")
|
||||
eventsCmd.Flags().StringVar(&eventsCmdFlags.actorID, "actor-id", "", "filter events by the specified actor ID (default is no filter)")
|
||||
}
|
||||
|
@ -47,6 +47,13 @@ func WithTailDuration(dur time.Duration) EventsOptionFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// WithActorID sets up Watcher to return events with the specified actor ID.
|
||||
func WithActorID(actorID string) EventsOptionFunc {
|
||||
return func(opts *machineapi.EventsRequest) {
|
||||
opts.WithActorId = actorID
|
||||
}
|
||||
}
|
||||
|
||||
// Events implements the proto.OSClient interface.
|
||||
func (c *Client) Events(ctx context.Context, opts ...EventsOptionFunc) (stream machineapi.MachineService_EventsClient, err error) {
|
||||
var req machineapi.EventsRequest
|
||||
@ -63,6 +70,7 @@ type Event struct {
|
||||
Node string
|
||||
TypeURL string
|
||||
ID string
|
||||
ActorID string
|
||||
Payload proto.Message
|
||||
}
|
||||
|
||||
@ -252,6 +260,7 @@ func UnmarshalEvent(event *machineapi.Event) (*Event, error) {
|
||||
TypeURL: typeURL,
|
||||
ID: event.Id,
|
||||
Payload: msg,
|
||||
ActorID: event.ActorId,
|
||||
}
|
||||
|
||||
if event.Metadata != nil {
|
||||
|
@ -1024,6 +1024,7 @@ talosctl events [flags]
|
||||
### Options
|
||||
|
||||
```
|
||||
--actor-id string filter events by the specified actor ID (default is no filter)
|
||||
--duration duration show events for the past duration interval (one second resolution, default is to show no history)
|
||||
-h, --help help for events
|
||||
--since string show events after the specified event ID (default is to show no history)
|
||||
|
Loading…
x
Reference in New Issue
Block a user