github-actions[bot] commented on code in PR #4493:
URL: https://github.com/apache/iggy/pull/4493#discussion_r4247038594


##########
foreign/go/client/tcp/tcp_utilities.go:
##########
@@ -38,6 +38,18 @@ func (c *IggyTcpClient) DescribeOptions(ctx context.Context, 
scope iggcon.Option
        return binaryserialization.DeserializeOptionSpecs(buffer)
 }
 
+// Snapshot returns a ZIP archive of the requested server diagnostics.
+func (c *IggyTcpClient) Snapshot(

Review Comment:
   warning: The transport caps the snapshot reply at 30 seconds 
(`responseReadTimeout`), and a caller's context deadline only shortens that 
wait. A collection that runs longer fails as `ErrDisconnected`, and the replay 
then meets the server's single-flight guard or collects the archive again. Give 
`GetSnapshotFileCode` its own, longer reply deadline, and state the budget in 
the `Snapshot` comment.



##########
foreign/go/internal/command/system.go:
##########
@@ -105,3 +108,26 @@ func (p *Ping) Code() Code {
 func (p *Ping) MarshalBinary() ([]byte, error) {
        return []byte{}, nil
 }
+
+type Snapshot struct {
+       Compression   iggcon.SnapshotCompression
+       SnapshotTypes []iggcon.SystemSnapshotType
+}
+
+func (s *Snapshot) Code() Code {
+       return GetSnapshotFileCode
+}
+
+func (s *Snapshot) MarshalBinary() ([]byte, error) {
+       if len(s.SnapshotTypes) > math.MaxUint8 {

Review Comment:
   warning: The encoder writes a zero count for an empty `snapshotTypes`, so 
the server answers with a valid ZIP that holds no sections. Reject an empty 
list with `ierror.ErrInvalidCommand`, because the caller gets no error for a 
request that captures nothing.



##########
foreign/go/internal/command/system_test.go:
##########
@@ -104,3 +106,92 @@ func TestEmptySystemCommandBodies(t *testing.T) {
                })
        }
 }
+
+func TestSnapshotMarshalBinary(t *testing.T) {
+       for _, test := range []struct {
+               name        string
+               compression iggcon.SnapshotCompression
+               want        byte
+       }{
+               {"stored", iggcon.SnapshotCompressionStored, 1},
+               {"deflated", iggcon.SnapshotCompressionDeflated, 2},
+               {"bzip2", iggcon.SnapshotCompressionBzip2, 3},
+               {"zstd", iggcon.SnapshotCompressionZstd, 4},
+               {"lzma", iggcon.SnapshotCompressionLzma, 5},
+               {"xz", iggcon.SnapshotCompressionXz, 6},
+               {"unknown compression", iggcon.SnapshotCompression(99), 99},
+       } {
+               t.Run(test.name, func(t *testing.T) {
+                       request := &Snapshot{
+                               Compression:   test.compression,
+                               SnapshotTypes: 
[]iggcon.SystemSnapshotType{iggcon.SystemSnapshotTypeTest},
+                       }
+                       if request.Code() != GetSnapshotFileCode {
+                               t.Fatalf("Snapshot code = %d, want %d", 
request.Code(), GetSnapshotFileCode)
+                       }
+                       got, err := request.MarshalBinary()
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       want := []byte{test.want, 1, 4}
+                       if !bytes.Equal(got, want) {
+                               t.Fatalf("Snapshot body = %v, want %v", got, 
want)
+                       }
+               })
+       }
+}
+
+func TestSnapshotMarshalBinaryTypes(t *testing.T) {
+       maxTypes := make([]iggcon.SystemSnapshotType, 255)

Review Comment:
   simplification: Both tests build a repeated slice with the same four-line 
fill loop. Replace it with 
`slices.Repeat([]​iggcon.SystemSnapshotType{iggcon.SystemSnapshotTypeTest}, 
255)`, which removes six lines. Also at line 183.



##########
foreign/go/internal/command/system.go:
##########
@@ -105,3 +108,26 @@ func (p *Ping) Code() Code {
 func (p *Ping) MarshalBinary() ([]byte, error) {
        return []byte{}, nil
 }
+
+type Snapshot struct {
+       Compression   iggcon.SnapshotCompression
+       SnapshotTypes []iggcon.SystemSnapshotType
+}
+
+func (s *Snapshot) Code() Code {
+       return GetSnapshotFileCode
+}
+
+func (s *Snapshot) MarshalBinary() ([]byte, error) {
+       if len(s.SnapshotTypes) > math.MaxUint8 {
+               return nil, fmt.Errorf("%w: snapshot type count exceeds %d", 
ierror.ErrInvalidCommand, math.MaxUint8)
+       }
+
+       body := make([]byte, 2+len(s.SnapshotTypes))
+       body[0] = byte(s.Compression)
+       body[1] = byte(len(s.SnapshotTypes))
+       for index, snapshotType := range s.SnapshotTypes {

Review Comment:
   nit: The encoder sends `SystemSnapshotTypeAll` beside another type 
unchecked, so the caller pays a round trip for a bare `invalid command`. Reject 
the mix locally, as the Node SDK does.



##########
foreign/go/contracts/system_snapshot_type.go:
##########
@@ -0,0 +1,30 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package iggcon
+
+type SystemSnapshotType uint8
+
+const (
+       SystemSnapshotTypeFileSystemOverview SystemSnapshotType = 1

Review Comment:
   nit: `SystemSnapshotTypeFileSystemOverview` splits the word differently from 
the server and every other SDK, which spell the section `FilesystemOverview`. 
Rename it to `SystemSnapshotTypeFilesystemOverview` before the release ships.



##########
foreign/go/contracts/client.go:
##########
@@ -66,6 +66,10 @@ type Client interface {
        // Authentication is required.
        DescribeOptions(ctx context.Context, scope OptionsScope) ([]OptionSpec, 
error)
 
+       // Snapshot returns a ZIP archive of the requested server diagnostics.
+       // Authentication is required. All must be requested without other 
types.

Review Comment:
   nit: The comment states that authentication alone is enough, but 
`get_snapshot` also needs the server-info permission (`read_servers` or 
`manage_servers`). Add it, as `GetStats` and `GetClients` do.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to