diff --git a/services/sysinfo/README.md b/services/sysinfo/README.md new file mode 100644 index 00000000..02daa38c --- /dev/null +++ b/services/sysinfo/README.md @@ -0,0 +1,69 @@ +# System Info +Service to retrieve system information from target system, such as kernel messages, uptime and journaling entries. + +# Usage + +### sanssh sysinfo uptime +Print the uptime of the system in below format: System_idx (ip:port) up for X days, X hours, X minutes, X seconds | total X seconds (X is a placeholder that will be replaced) + +```bash +sanssh sysinfo uptime +``` +Where: +- `` common sanssh arguments + +Examples: +```bash +# Get data from a yml file +sanssh --targets=localhost sysinfo uptime +``` + +### sanssh sysinfo dmesg +Print the messages from kernel ring buffer. + +```bash +sanssh sysinfo dmesg [--tail==] [--grep=] [-i] [-v] [--timeout=] +``` + +Where: +- `` common sanssh arguments +- `` specify number of lines to `tail` +- `` grep regex pattern to filter out messages with +- `-i` - ignore grep case +- `-v` - inverted match grep +- `` timeout collection of kernel messages in this number of seconds, default is 2 seconds + +Examples: +```bash +### Default +sanssh --targets localhost sysinfo dmesg +### Get messages matching NVMe SSD pattern +sanssh --targets localhost sysinfo dmesg --grep "nvme1n1.*ssd.*" +### Get messages not related to BTRFS (ignoring case) +sanssh --targets localhost sysinfo dmesg -grep "btrfs" -i -v +### Collect messages for 10 seconds +sanssh --targets localhost sysinfo dmesg -grep "btrfs" -i -v --timeout=10 +``` + +### sanssh sysinfo journalctl +Get the log entries stored in journald by systemd-journald.service + +```bash +sanssh sysinfo djournalctl [--since|--S=] [--until|-U=] [-tail=] [-u|-unit=] [--json] +``` + +Where: +- `` common sanssh arguments +- `` Sets the date (YYYY-MM-DD HH:MM:SS) we want to filter from +- `` Sets the date (YYYY-MM-DD HH:MM:SS) we want to filter until +- `` - If positive, the latest n records to fetch. By default, fetch latest 100 records. The upper limit is 10000 for now +- `` - Sets systemd unit to filter messages +- `--json` - Print the journal entries in JSON format(can work with jq for better visualization) + +Examples: +```bash +### Get 5 journalctl entries in json format between 18th and 19th of December 2024 +sanssh --targets localhost sysinfo journalctl --json --tail 5 --since "2024-12-18 00:00:00" --until "2024-12-19 00:00:00" +### Read entries from default.target unit +sanssh --targets localhost sysinfo journalctl --unit default.target +``` diff --git a/services/sysinfo/client/client.go b/services/sysinfo/client/client.go index 3a117a71..3206b956 100644 --- a/services/sysinfo/client/client.go +++ b/services/sysinfo/client/client.go @@ -116,12 +116,13 @@ type dmesgCmd struct { grep string ignoreCase bool invertMatch bool + timeout int64 } func (*dmesgCmd) Name() string { return "dmesg" } func (*dmesgCmd) Synopsis() string { return "View the messages in kernel ring buffer" } func (*dmesgCmd) Usage() string { - return `dmesg [--tail=N] [--grep=PATTERN] [-i] [-v]: + return `dmesg [--tail=N] [--grep=PATTERN] [-i] [-v] [--timeout=N]: Print the messages from kernel ring buffer. ` } @@ -131,6 +132,7 @@ func (p *dmesgCmd) SetFlags(f *flag.FlagSet) { f.Int64Var(&p.tail, "tail", -1, "tail the latest n lines") f.BoolVar(&p.ignoreCase, "i", false, "ignore case") f.BoolVar(&p.invertMatch, "v", false, "invert match") + f.Int64Var(&p.timeout, "timeout", 2, "timeout collection of messages after N seconds, default is 2 seconds") } func (p *dmesgCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { @@ -142,6 +144,7 @@ func (p *dmesgCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa Grep: p.grep, IgnoreCase: p.ignoreCase, InvertMatch: p.invertMatch, + Timeout: p.timeout, } stream, err := c.DmesgOneMany(ctx, req) if err != nil { diff --git a/services/sysinfo/server/sysinfo.go b/services/sysinfo/server/sysinfo.go index 44926cb4..62c93d83 100644 --- a/services/sysinfo/server/sysinfo.go +++ b/services/sysinfo/server/sysinfo.go @@ -71,7 +71,7 @@ func (s *server) Dmesg(req *pb.DmesgRequest, stream pb.SysInfo_DmesgServer) erro return status.Error(codes.InvalidArgument, "must provide grep argument before setting ignore_case or invert_match") } - records, err := getKernelMessages() + records, err := getKernelMessages(req.Timeout) if err != nil { recorder.CounterOrLog(ctx, sysinfoDmesgFailureCounter, 1, attribute.String("reason", "get kernel message error")) return status.Errorf(codes.InvalidArgument, "can't get kernel message %v", err) diff --git a/services/sysinfo/server/sysinfo_linux.go b/services/sysinfo/server/sysinfo_linux.go index f83b1ac8..4ec1a76f 100644 --- a/services/sysinfo/server/sysinfo_linux.go +++ b/services/sysinfo/server/sysinfo_linux.go @@ -86,7 +86,8 @@ var getUptime = func() (time.Duration, error) { // we set 2 seconds timeout to explicitly close the channel // If the package releases new feature to support non-blocking read, we can // make corresponding changes below to get rid of hard code timeout setting -var getKernelMessages = func() ([]*pb.DmsgRecord, error) { +var getKernelMessages = func(providedTimeout int64) ([]*pb.DmsgRecord, error) { + timeout := getTimeout(providedTimeout) parser, err := getKmsgParser() if err != nil { return nil, err @@ -106,7 +107,7 @@ var getKernelMessages = func() ([]*pb.DmsgRecord, error) { Message: msg.Message, Time: timestamppb.New(msg.Timestamp), }) - case <-time.After(2 * time.Second): + case <-time.After(timeout): parser.Close() done = true } @@ -195,3 +196,16 @@ var getJournalRecordsAndSend = func(ctx context.Context, req *pb.JournalRequest, } return nil } + +func getTimeout(provided int64) time.Duration { + const maxTimeout = 30 * time.Second + const minTimeout = 2 * time.Second + timeout := time.Duration(provided) * time.Second + if timeout > maxTimeout { + timeout = maxTimeout + } + if timeout < minTimeout { + timeout = minTimeout + } + return timeout +} diff --git a/services/sysinfo/server/sysinfo_linux_test.go b/services/sysinfo/server/sysinfo_linux_test.go index 60c900fb..874ce83b 100644 --- a/services/sysinfo/server/sysinfo_linux_test.go +++ b/services/sysinfo/server/sysinfo_linux_test.go @@ -252,8 +252,8 @@ func TestDmesg(t *testing.T) { }) } - getKernelMessages = func() ([]*pb.DmsgRecord, error) { - _, err := savedGetKernelMessages() + getKernelMessages = func(int32) ([]*pb.DmsgRecord, error) { + _, err := savedGetKernelMessages(0) if err != nil { return nil, err } diff --git a/services/sysinfo/sysinfo.pb.go b/services/sysinfo/sysinfo.pb.go index f1e005c6..b776861e 100644 --- a/services/sysinfo/sysinfo.pb.go +++ b/services/sysinfo/sysinfo.pb.go @@ -15,8 +15,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.32.0 -// protoc v5.26.1 +// protoc-gen-go v1.34.2 +// protoc v5.29.1 // source: sysinfo.proto package sysinfo @@ -97,6 +97,9 @@ type DmesgRequest struct { Grep string `protobuf:"bytes,2,opt,name=grep,proto3" json:"grep,omitempty"` IgnoreCase bool `protobuf:"varint,3,opt,name=ignore_case,json=ignoreCase,proto3" json:"ignore_case,omitempty"` InvertMatch bool `protobuf:"varint,4,opt,name=invert_match,json=invertMatch,proto3" json:"invert_match,omitempty"` + // time in seconds after which dmesg output will be stopped and the result returned + // default is 2 seconds, minimum is 2s and maximum is 30s + Timeout int64 `protobuf:"varint,5,opt,name=timeout,proto3" json:"timeout,omitempty"` } func (x *DmesgRequest) Reset() { @@ -159,6 +162,13 @@ func (x *DmesgRequest) GetInvertMatch() bool { return false } +func (x *DmesgRequest) GetTimeout() int64 { + if x != nil { + return x.Timeout + } + return 0 +} + // DmesgReply contains the messages from kernel type DmesgReply struct { state protoimpl.MessageState @@ -576,7 +586,7 @@ var file_sysinfo_proto_rawDesc = []byte{ 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, - 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x22, 0x85, 0x01, 0x0a, 0x0c, 0x44, 0x6d, 0x65, 0x73, + 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x22, 0x9f, 0x01, 0x0a, 0x0c, 0x44, 0x6d, 0x65, 0x73, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x61, 0x69, 0x6c, 0x5f, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x74, 0x61, 0x69, 0x6c, 0x4c, 0x69, 0x6e, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x67, 0x72, 0x65, 0x70, 0x18, @@ -584,77 +594,78 @@ var file_sysinfo_proto_rawDesc = []byte{ 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x73, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x43, 0x61, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x69, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x0b, 0x69, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x22, - 0x39, 0x0a, 0x0a, 0x44, 0x6d, 0x65, 0x73, 0x67, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x2b, 0x0a, - 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, - 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x44, 0x6d, 0x73, 0x67, 0x52, 0x65, 0x63, 0x6f, - 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x22, 0x56, 0x0a, 0x0a, 0x44, 0x6d, - 0x73, 0x67, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x2e, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, - 0x6d, 0x70, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, - 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x22, 0xd8, 0x01, 0x0a, 0x0e, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x73, 0x69, - 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x53, 0x69, 0x6e, 0x63, 0x65, - 0x12, 0x39, 0x0a, 0x0a, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x74, 0x69, 0x6c, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x74, 0x69, 0x6c, 0x12, 0x1b, 0x0a, 0x09, 0x74, - 0x61, 0x69, 0x6c, 0x5f, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, - 0x74, 0x61, 0x69, 0x6c, 0x4c, 0x69, 0x6e, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x6e, 0x69, 0x74, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x12, 0x1f, 0x0a, 0x0b, - 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x0a, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x4a, 0x73, 0x6f, 0x6e, 0x22, 0x8b, 0x01, - 0x0a, 0x0c, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x32, - 0x0a, 0x07, 0x6a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x16, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, - 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x48, 0x00, 0x52, 0x07, 0x6a, 0x6f, 0x75, 0x72, 0x6e, - 0x61, 0x6c, 0x12, 0x3b, 0x0a, 0x0a, 0x6a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x61, 0x77, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, - 0x2e, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x61, - 0x77, 0x48, 0x00, 0x52, 0x0a, 0x6a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x61, 0x77, 0x42, - 0x0a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xcf, 0x01, 0x0a, 0x0d, - 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x49, 0x0a, - 0x12, 0x72, 0x65, 0x61, 0x6c, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, - 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x11, 0x72, 0x65, 0x61, 0x6c, 0x74, 0x69, 0x6d, 0x65, 0x54, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x68, 0x6f, 0x73, 0x74, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x68, 0x6f, 0x73, 0x74, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2b, 0x0a, 0x11, 0x73, 0x79, 0x73, 0x6c, 0x6f, 0x67, 0x5f, 0x69, - 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x10, 0x73, 0x79, 0x73, 0x6c, 0x6f, 0x67, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, - 0x72, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, - 0x70, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x88, 0x01, - 0x0a, 0x10, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, - 0x61, 0x77, 0x12, 0x3a, 0x0a, 0x05, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x24, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x4a, 0x6f, 0x75, 0x72, - 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x61, 0x77, 0x2e, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x1a, 0x38, - 0x0a, 0x0a, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xbb, 0x01, 0x0a, 0x07, 0x53, 0x79, 0x73, - 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x38, 0x0a, 0x06, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x16, + 0x28, 0x08, 0x52, 0x0b, 0x69, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x12, + 0x18, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, 0x39, 0x0a, 0x0a, 0x44, 0x6d, 0x65, + 0x73, 0x67, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x2b, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, + 0x6f, 0x2e, 0x44, 0x6d, 0x73, 0x67, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, + 0x63, 0x6f, 0x72, 0x64, 0x22, 0x56, 0x0a, 0x0a, 0x44, 0x6d, 0x73, 0x67, 0x52, 0x65, 0x63, 0x6f, + 0x72, 0x64, 0x12, 0x2e, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x04, 0x74, 0x69, + 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xd8, 0x01, 0x0a, + 0x0e, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x39, 0x0a, 0x0a, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x73, 0x69, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, + 0x09, 0x74, 0x69, 0x6d, 0x65, 0x53, 0x69, 0x6e, 0x63, 0x65, 0x12, 0x39, 0x0a, 0x0a, 0x74, 0x69, + 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x74, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x14, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, - 0x2e, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x37, - 0x0a, 0x05, 0x44, 0x6d, 0x65, 0x73, 0x67, 0x12, 0x15, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, - 0x6f, 0x2e, 0x44, 0x6d, 0x65, 0x73, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, - 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x44, 0x6d, 0x65, 0x73, 0x67, 0x52, 0x65, - 0x70, 0x6c, 0x79, 0x22, 0x00, 0x30, 0x01, 0x12, 0x3d, 0x0a, 0x07, 0x4a, 0x6f, 0x75, 0x72, 0x6e, - 0x61, 0x6c, 0x12, 0x17, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x4a, 0x6f, 0x75, - 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x53, 0x79, - 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x70, - 0x6c, 0x79, 0x22, 0x00, 0x30, 0x01, 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x53, 0x6e, 0x6f, 0x77, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x2d, 0x4c, - 0x61, 0x62, 0x73, 0x2f, 0x73, 0x61, 0x6e, 0x73, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x2f, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x73, 0x79, 0x73, 0x69, 0x6e, 0x66, 0x6f, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, + 0x55, 0x6e, 0x74, 0x69, 0x6c, 0x12, 0x1b, 0x0a, 0x09, 0x74, 0x61, 0x69, 0x6c, 0x5f, 0x6c, 0x69, + 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x74, 0x61, 0x69, 0x6c, 0x4c, 0x69, + 0x6e, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, + 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x65, 0x6e, 0x61, + 0x62, 0x6c, 0x65, 0x4a, 0x73, 0x6f, 0x6e, 0x22, 0x8b, 0x01, 0x0a, 0x0c, 0x4a, 0x6f, 0x75, 0x72, + 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x32, 0x0a, 0x07, 0x6a, 0x6f, 0x75, 0x72, + 0x6e, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x53, 0x79, 0x73, 0x49, + 0x6e, 0x66, 0x6f, 0x2e, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, + 0x64, 0x48, 0x00, 0x52, 0x07, 0x6a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x12, 0x3b, 0x0a, 0x0a, + 0x6a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x61, 0x77, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x19, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x4a, 0x6f, 0x75, 0x72, 0x6e, + 0x61, 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x61, 0x77, 0x48, 0x00, 0x52, 0x0a, 0x6a, + 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x61, 0x77, 0x42, 0x0a, 0x0a, 0x08, 0x72, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xcf, 0x01, 0x0a, 0x0d, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, + 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x49, 0x0a, 0x12, 0x72, 0x65, 0x61, 0x6c, 0x74, + 0x69, 0x6d, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, + 0x11, 0x72, 0x65, 0x61, 0x6c, 0x74, 0x69, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x68, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x68, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2b, + 0x0a, 0x11, 0x73, 0x79, 0x73, 0x6c, 0x6f, 0x67, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, + 0x69, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x73, 0x79, 0x73, 0x6c, 0x6f, + 0x67, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x70, + 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x70, 0x69, 0x64, 0x12, 0x18, 0x0a, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x88, 0x01, 0x0a, 0x10, 0x4a, 0x6f, 0x75, 0x72, + 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x61, 0x77, 0x12, 0x3a, 0x0a, 0x05, + 0x65, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x53, 0x79, + 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x63, + 0x6f, 0x72, 0x64, 0x52, 0x61, 0x77, 0x2e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x52, 0x05, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x1a, 0x38, 0x0a, 0x0a, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x32, 0xbb, 0x01, 0x0a, 0x07, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x38, + 0x0a, 0x06, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x1a, 0x14, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x55, 0x70, 0x74, 0x69, 0x6d, + 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x05, 0x44, 0x6d, 0x65, 0x73, + 0x67, 0x12, 0x15, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x44, 0x6d, 0x65, 0x73, + 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, + 0x66, 0x6f, 0x2e, 0x44, 0x6d, 0x65, 0x73, 0x67, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x30, + 0x01, 0x12, 0x3d, 0x0a, 0x07, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x12, 0x17, 0x2e, 0x53, + 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x53, 0x79, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x2e, + 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x30, 0x01, + 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x53, + 0x6e, 0x6f, 0x77, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x2d, 0x4c, 0x61, 0x62, 0x73, 0x2f, 0x73, 0x61, + 0x6e, 0x73, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, + 0x2f, 0x73, 0x79, 0x73, 0x69, 0x6e, 0x66, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -670,7 +681,7 @@ func file_sysinfo_proto_rawDescGZIP() []byte { } var file_sysinfo_proto_msgTypes = make([]protoimpl.MessageInfo, 9) -var file_sysinfo_proto_goTypes = []interface{}{ +var file_sysinfo_proto_goTypes = []any{ (*UptimeReply)(nil), // 0: SysInfo.UptimeReply (*DmesgRequest)(nil), // 1: SysInfo.DmesgRequest (*DmesgReply)(nil), // 2: SysInfo.DmesgReply @@ -713,7 +724,7 @@ func file_sysinfo_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_sysinfo_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_sysinfo_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*UptimeReply); i { case 0: return &v.state @@ -725,7 +736,7 @@ func file_sysinfo_proto_init() { return nil } } - file_sysinfo_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_sysinfo_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*DmesgRequest); i { case 0: return &v.state @@ -737,7 +748,7 @@ func file_sysinfo_proto_init() { return nil } } - file_sysinfo_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_sysinfo_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*DmesgReply); i { case 0: return &v.state @@ -749,7 +760,7 @@ func file_sysinfo_proto_init() { return nil } } - file_sysinfo_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_sysinfo_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*DmsgRecord); i { case 0: return &v.state @@ -761,7 +772,7 @@ func file_sysinfo_proto_init() { return nil } } - file_sysinfo_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_sysinfo_proto_msgTypes[4].Exporter = func(v any, i int) any { switch v := v.(*JournalRequest); i { case 0: return &v.state @@ -773,7 +784,7 @@ func file_sysinfo_proto_init() { return nil } } - file_sysinfo_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_sysinfo_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*JournalReply); i { case 0: return &v.state @@ -785,7 +796,7 @@ func file_sysinfo_proto_init() { return nil } } - file_sysinfo_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_sysinfo_proto_msgTypes[6].Exporter = func(v any, i int) any { switch v := v.(*JournalRecord); i { case 0: return &v.state @@ -797,7 +808,7 @@ func file_sysinfo_proto_init() { return nil } } - file_sysinfo_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_sysinfo_proto_msgTypes[7].Exporter = func(v any, i int) any { switch v := v.(*JournalRecordRaw); i { case 0: return &v.state @@ -810,7 +821,7 @@ func file_sysinfo_proto_init() { } } } - file_sysinfo_proto_msgTypes[5].OneofWrappers = []interface{}{ + file_sysinfo_proto_msgTypes[5].OneofWrappers = []any{ (*JournalReply_Journal)(nil), (*JournalReply_JournalRaw)(nil), } diff --git a/services/sysinfo/sysinfo.proto b/services/sysinfo/sysinfo.proto index 8b580dc5..c02584b8 100644 --- a/services/sysinfo/sysinfo.proto +++ b/services/sysinfo/sysinfo.proto @@ -46,6 +46,9 @@ message DmesgRequest { string grep = 2; bool ignore_case = 3; bool invert_match = 4; + // time in seconds after which dmesg output will be stopped and the result returned + // default is 2 seconds, minimum is 2s and maximum is 30s + int64 timeout = 5; } // DmesgReply contains the messages from kernel diff --git a/services/sysinfo/sysinfo_grpc.pb.go b/services/sysinfo/sysinfo_grpc.pb.go index b308031c..9d4123f6 100644 --- a/services/sysinfo/sysinfo_grpc.pb.go +++ b/services/sysinfo/sysinfo_grpc.pb.go @@ -15,8 +15,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v5.26.1 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.29.1 // source: sysinfo.proto package sysinfo @@ -31,8 +31,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( SysInfo_Uptime_FullMethodName = "/SysInfo.SysInfo/Uptime" @@ -43,13 +43,15 @@ const ( // SysInfoClient is the client API for SysInfo service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// The SysInfo service definition. type SysInfoClient interface { // Uptime return Uptime(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*UptimeReply, error) // display kernel-related messages - Dmesg(ctx context.Context, in *DmesgRequest, opts ...grpc.CallOption) (SysInfo_DmesgClient, error) + Dmesg(ctx context.Context, in *DmesgRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[DmesgReply], error) // Journal returns journal entries collected by systemd journald service - Journal(ctx context.Context, in *JournalRequest, opts ...grpc.CallOption) (SysInfo_JournalClient, error) + Journal(ctx context.Context, in *JournalRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[JournalReply], error) } type sysInfoClient struct { @@ -61,20 +63,22 @@ func NewSysInfoClient(cc grpc.ClientConnInterface) SysInfoClient { } func (c *sysInfoClient) Uptime(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*UptimeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(UptimeReply) - err := c.cc.Invoke(ctx, SysInfo_Uptime_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, SysInfo_Uptime_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } return out, nil } -func (c *sysInfoClient) Dmesg(ctx context.Context, in *DmesgRequest, opts ...grpc.CallOption) (SysInfo_DmesgClient, error) { - stream, err := c.cc.NewStream(ctx, &SysInfo_ServiceDesc.Streams[0], SysInfo_Dmesg_FullMethodName, opts...) +func (c *sysInfoClient) Dmesg(ctx context.Context, in *DmesgRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[DmesgReply], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &SysInfo_ServiceDesc.Streams[0], SysInfo_Dmesg_FullMethodName, cOpts...) if err != nil { return nil, err } - x := &sysInfoDmesgClient{stream} + x := &grpc.GenericClientStream[DmesgRequest, DmesgReply]{ClientStream: stream} if err := x.ClientStream.SendMsg(in); err != nil { return nil, err } @@ -84,29 +88,16 @@ func (c *sysInfoClient) Dmesg(ctx context.Context, in *DmesgRequest, opts ...grp return x, nil } -type SysInfo_DmesgClient interface { - Recv() (*DmesgReply, error) - grpc.ClientStream -} - -type sysInfoDmesgClient struct { - grpc.ClientStream -} - -func (x *sysInfoDmesgClient) Recv() (*DmesgReply, error) { - m := new(DmesgReply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type SysInfo_DmesgClient = grpc.ServerStreamingClient[DmesgReply] -func (c *sysInfoClient) Journal(ctx context.Context, in *JournalRequest, opts ...grpc.CallOption) (SysInfo_JournalClient, error) { - stream, err := c.cc.NewStream(ctx, &SysInfo_ServiceDesc.Streams[1], SysInfo_Journal_FullMethodName, opts...) +func (c *sysInfoClient) Journal(ctx context.Context, in *JournalRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[JournalReply], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &SysInfo_ServiceDesc.Streams[1], SysInfo_Journal_FullMethodName, cOpts...) if err != nil { return nil, err } - x := &sysInfoJournalClient{stream} + x := &grpc.GenericClientStream[JournalRequest, JournalReply]{ClientStream: stream} if err := x.ClientStream.SendMsg(in); err != nil { return nil, err } @@ -116,48 +107,40 @@ func (c *sysInfoClient) Journal(ctx context.Context, in *JournalRequest, opts .. return x, nil } -type SysInfo_JournalClient interface { - Recv() (*JournalReply, error) - grpc.ClientStream -} - -type sysInfoJournalClient struct { - grpc.ClientStream -} - -func (x *sysInfoJournalClient) Recv() (*JournalReply, error) { - m := new(JournalReply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type SysInfo_JournalClient = grpc.ServerStreamingClient[JournalReply] // SysInfoServer is the server API for SysInfo service. // All implementations should embed UnimplementedSysInfoServer -// for forward compatibility +// for forward compatibility. +// +// The SysInfo service definition. type SysInfoServer interface { // Uptime return Uptime(context.Context, *emptypb.Empty) (*UptimeReply, error) // display kernel-related messages - Dmesg(*DmesgRequest, SysInfo_DmesgServer) error + Dmesg(*DmesgRequest, grpc.ServerStreamingServer[DmesgReply]) error // Journal returns journal entries collected by systemd journald service - Journal(*JournalRequest, SysInfo_JournalServer) error + Journal(*JournalRequest, grpc.ServerStreamingServer[JournalReply]) error } -// UnimplementedSysInfoServer should be embedded to have forward compatible implementations. -type UnimplementedSysInfoServer struct { -} +// UnimplementedSysInfoServer should be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedSysInfoServer struct{} func (UnimplementedSysInfoServer) Uptime(context.Context, *emptypb.Empty) (*UptimeReply, error) { return nil, status.Errorf(codes.Unimplemented, "method Uptime not implemented") } -func (UnimplementedSysInfoServer) Dmesg(*DmesgRequest, SysInfo_DmesgServer) error { +func (UnimplementedSysInfoServer) Dmesg(*DmesgRequest, grpc.ServerStreamingServer[DmesgReply]) error { return status.Errorf(codes.Unimplemented, "method Dmesg not implemented") } -func (UnimplementedSysInfoServer) Journal(*JournalRequest, SysInfo_JournalServer) error { +func (UnimplementedSysInfoServer) Journal(*JournalRequest, grpc.ServerStreamingServer[JournalReply]) error { return status.Errorf(codes.Unimplemented, "method Journal not implemented") } +func (UnimplementedSysInfoServer) testEmbeddedByValue() {} // UnsafeSysInfoServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to SysInfoServer will @@ -167,6 +150,13 @@ type UnsafeSysInfoServer interface { } func RegisterSysInfoServer(s grpc.ServiceRegistrar, srv SysInfoServer) { + // If the following call pancis, it indicates UnimplementedSysInfoServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&SysInfo_ServiceDesc, srv) } @@ -193,42 +183,22 @@ func _SysInfo_Dmesg_Handler(srv interface{}, stream grpc.ServerStream) error { if err := stream.RecvMsg(m); err != nil { return err } - return srv.(SysInfoServer).Dmesg(m, &sysInfoDmesgServer{stream}) -} - -type SysInfo_DmesgServer interface { - Send(*DmesgReply) error - grpc.ServerStream -} - -type sysInfoDmesgServer struct { - grpc.ServerStream + return srv.(SysInfoServer).Dmesg(m, &grpc.GenericServerStream[DmesgRequest, DmesgReply]{ServerStream: stream}) } -func (x *sysInfoDmesgServer) Send(m *DmesgReply) error { - return x.ServerStream.SendMsg(m) -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type SysInfo_DmesgServer = grpc.ServerStreamingServer[DmesgReply] func _SysInfo_Journal_Handler(srv interface{}, stream grpc.ServerStream) error { m := new(JournalRequest) if err := stream.RecvMsg(m); err != nil { return err } - return srv.(SysInfoServer).Journal(m, &sysInfoJournalServer{stream}) -} - -type SysInfo_JournalServer interface { - Send(*JournalReply) error - grpc.ServerStream + return srv.(SysInfoServer).Journal(m, &grpc.GenericServerStream[JournalRequest, JournalReply]{ServerStream: stream}) } -type sysInfoJournalServer struct { - grpc.ServerStream -} - -func (x *sysInfoJournalServer) Send(m *JournalReply) error { - return x.ServerStream.SendMsg(m) -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type SysInfo_JournalServer = grpc.ServerStreamingServer[JournalReply] // SysInfo_ServiceDesc is the grpc.ServiceDesc for SysInfo service. // It's only intended for direct use with grpc.RegisterService,