mmodzelewski commented on code in PR #3032:
URL: https://github.com/apache/iggy/pull/3032#discussion_r3071308714
##########
foreign/go/contracts/stats.go:
##########
@@ -17,27 +17,142 @@
package iggcon
+import (
+ "fmt"
+
+ "github.com/apache/iggy/foreign/go/internal/codec"
+)
+
+// CacheMetrics holds cache hit/miss statistics for a single partition.
+type CacheMetrics struct {
+ StreamId uint32 `json:"stream_id"`
+ TopicId uint32 `json:"topic_id"`
+ PartitionId uint32 `json:"partition_id"`
+ Hits uint64 `json:"hits"`
+ Misses uint64 `json:"misses"`
+ HitRatio float32 `json:"hit_ratio"`
+}
+
+// cacheMetricsWireSize is the fixed size of a CacheMetrics entry on the wire:
+// stream_id(4) + topic_id(4) + partition_id(4) + hits(8) + misses(8) +
hit_ratio(4) = 32.
+const cacheMetricsWireSize = 4 + 4 + 4 + 8 + 8 + 4
+
type Stats struct {
- ProcessId uint32 `json:"process_id"`
- CpuUsage float32 `json:"cpu_usage"`
- TotalCpuUsage float32 `json:"total_cpu_usage"`
- MemoryUsage uint64 `json:"memory_usage"`
- TotalMemory uint64 `json:"total_memory"`
- AvailableMemory uint64 `json:"available_memory"`
- RunTime uint64 `json:"run_time"`
- StartTime uint64 `json:"start_time"`
- ReadBytes uint64 `json:"read_bytes"`
- WrittenBytes uint64 `json:"written_bytes"`
- MessagesSizeBytes uint64 `json:"messages_size_bytes"`
- StreamsCount uint32 `json:"streams_count"`
- TopicsCount uint32 `json:"topics_count"`
- PartitionsCount uint32 `json:"partitions_count"`
- SegmentsCount uint32 `json:"segments_count"`
- MessagesCount uint64 `json:"messages_count"`
- ClientsCount uint32 `json:"clients_count"`
- ConsumerGroupsCount uint32 `json:"consumer_groups_count"`
- Hostname string `json:"hostname"`
- OsName string `json:"os_name"`
- OsVersion string `json:"os_version"`
- KernelVersion string `json:"kernel_version"`
+ ProcessId uint32 `json:"process_id"`
+ CpuUsage float32 `json:"cpu_usage"`
+ TotalCpuUsage float32 `json:"total_cpu_usage"`
+ MemoryUsage uint64 `json:"memory_usage"`
+ TotalMemory uint64 `json:"total_memory"`
+ AvailableMemory uint64 `json:"available_memory"`
+ RunTime uint64 `json:"run_time"`
+ StartTime uint64 `json:"start_time"`
+ ReadBytes uint64 `json:"read_bytes"`
+ WrittenBytes uint64 `json:"written_bytes"`
+ MessagesSizeBytes uint64 `json:"messages_size_bytes"`
+ StreamsCount uint32 `json:"streams_count"`
+ TopicsCount uint32 `json:"topics_count"`
+ PartitionsCount uint32 `json:"partitions_count"`
+ SegmentsCount uint32 `json:"segments_count"`
+ MessagesCount uint64 `json:"messages_count"`
+ ClientsCount uint32 `json:"clients_count"`
+ ConsumerGroupsCount uint32 `json:"consumer_groups_count"`
+ Hostname string `json:"hostname"`
+ OsName string `json:"os_name"`
+ OsVersion string `json:"os_version"`
+ KernelVersion string `json:"kernel_version"`
+ IggyServerVersion string `json:"iggy_server_version"`
+ IggyServerSemver *uint32 `json:"iggy_server_semver,omitempty"`
+ CacheMetrics []CacheMetrics `json:"cache_metrics"`
+ ThreadsCount uint32 `json:"threads_count"`
+ FreeDiskSpace uint64 `json:"free_disk_space"`
+ TotalDiskSpace uint64 `json:"total_disk_space"`
+}
+
+func (cm *CacheMetrics) MarshalBinary() ([]byte, error) {
+ w := codec.NewWriterCap(32)
+ w.U32(cm.StreamId)
+ w.U32(cm.TopicId)
+ w.U32(cm.PartitionId)
+ w.U64(cm.Hits)
+ w.U64(cm.Misses)
+ w.F32(cm.HitRatio)
+ return w.Bytes(), w.Err()
+}
+
+func (cm *CacheMetrics) UnmarshalBinary(data []byte) error {
+ r := codec.NewReader(data)
+ cm.StreamId = r.U32()
+ cm.TopicId = r.U32()
+ cm.PartitionId = r.U32()
+ cm.Hits = r.U64()
+ cm.Misses = r.U64()
+ cm.HitRatio = r.F32()
+ return r.Err()
+}
+
+func (s *Stats) UnmarshalBinary(payload []byte) error {
+ r := codec.NewReader(payload)
+ s.ProcessId = r.U32()
+ s.CpuUsage = r.F32()
+ s.TotalCpuUsage = r.F32()
+ s.MemoryUsage = r.U64()
+ s.TotalMemory = r.U64()
+ s.AvailableMemory = r.U64()
+ s.RunTime = r.U64()
+ s.StartTime = r.U64()
+ s.ReadBytes = r.U64()
+ s.WrittenBytes = r.U64()
+ s.MessagesSizeBytes = r.U64()
+ s.StreamsCount = r.U32()
+ s.TopicsCount = r.U32()
+ s.PartitionsCount = r.U32()
+ s.SegmentsCount = r.U32()
+ s.MessagesCount = r.U64()
+ s.ClientsCount = r.U32()
+ s.ConsumerGroupsCount = r.U32()
+ s.Hostname = r.U32LenStr()
+ s.OsName = r.U32LenStr()
+ s.OsVersion = r.U32LenStr()
+ s.KernelVersion = r.U32LenStr()
+ s.IggyServerVersion = r.U32LenStr()
+
+ if r.Err() != nil {
+ return r.Err()
+ }
+
+ // iggy_server_semver is optional. If at least 8 bytes remain, the next
4
Review Comment:
Server encoding has been fixed and now the format is stable. If the semver
is missing, it will be encoded as 0, so the following check is no longer
required.
##########
foreign/go/contracts/stats.go:
##########
@@ -17,27 +17,142 @@
package iggcon
+import (
+ "fmt"
+
+ "github.com/apache/iggy/foreign/go/internal/codec"
+)
+
+// CacheMetrics holds cache hit/miss statistics for a single partition.
+type CacheMetrics struct {
+ StreamId uint32 `json:"stream_id"`
Review Comment:
Will this struct work for HTTP? Metrics are serialized as Map with computed
strings as keys.
```
impl CacheMetricsKey {
pub fn to_string_key(&self) -> String {
format!("{}-{}-{}", self.stream_id, self.topic_id, self.partition_id)
}
}
```
##########
foreign/go/contracts/stats.go:
##########
@@ -17,27 +17,142 @@
package iggcon
+import (
+ "fmt"
+
+ "github.com/apache/iggy/foreign/go/internal/codec"
+)
+
+// CacheMetrics holds cache hit/miss statistics for a single partition.
+type CacheMetrics struct {
+ StreamId uint32 `json:"stream_id"`
+ TopicId uint32 `json:"topic_id"`
+ PartitionId uint32 `json:"partition_id"`
+ Hits uint64 `json:"hits"`
+ Misses uint64 `json:"misses"`
+ HitRatio float32 `json:"hit_ratio"`
+}
+
+// cacheMetricsWireSize is the fixed size of a CacheMetrics entry on the wire:
+// stream_id(4) + topic_id(4) + partition_id(4) + hits(8) + misses(8) +
hit_ratio(4) = 32.
+const cacheMetricsWireSize = 4 + 4 + 4 + 8 + 8 + 4
+
type Stats struct {
- ProcessId uint32 `json:"process_id"`
- CpuUsage float32 `json:"cpu_usage"`
- TotalCpuUsage float32 `json:"total_cpu_usage"`
- MemoryUsage uint64 `json:"memory_usage"`
- TotalMemory uint64 `json:"total_memory"`
- AvailableMemory uint64 `json:"available_memory"`
- RunTime uint64 `json:"run_time"`
- StartTime uint64 `json:"start_time"`
- ReadBytes uint64 `json:"read_bytes"`
- WrittenBytes uint64 `json:"written_bytes"`
- MessagesSizeBytes uint64 `json:"messages_size_bytes"`
- StreamsCount uint32 `json:"streams_count"`
- TopicsCount uint32 `json:"topics_count"`
- PartitionsCount uint32 `json:"partitions_count"`
- SegmentsCount uint32 `json:"segments_count"`
- MessagesCount uint64 `json:"messages_count"`
- ClientsCount uint32 `json:"clients_count"`
- ConsumerGroupsCount uint32 `json:"consumer_groups_count"`
- Hostname string `json:"hostname"`
- OsName string `json:"os_name"`
- OsVersion string `json:"os_version"`
- KernelVersion string `json:"kernel_version"`
+ ProcessId uint32 `json:"process_id"`
+ CpuUsage float32 `json:"cpu_usage"`
+ TotalCpuUsage float32 `json:"total_cpu_usage"`
+ MemoryUsage uint64 `json:"memory_usage"`
+ TotalMemory uint64 `json:"total_memory"`
+ AvailableMemory uint64 `json:"available_memory"`
+ RunTime uint64 `json:"run_time"`
+ StartTime uint64 `json:"start_time"`
+ ReadBytes uint64 `json:"read_bytes"`
+ WrittenBytes uint64 `json:"written_bytes"`
+ MessagesSizeBytes uint64 `json:"messages_size_bytes"`
+ StreamsCount uint32 `json:"streams_count"`
+ TopicsCount uint32 `json:"topics_count"`
+ PartitionsCount uint32 `json:"partitions_count"`
+ SegmentsCount uint32 `json:"segments_count"`
+ MessagesCount uint64 `json:"messages_count"`
+ ClientsCount uint32 `json:"clients_count"`
+ ConsumerGroupsCount uint32 `json:"consumer_groups_count"`
+ Hostname string `json:"hostname"`
+ OsName string `json:"os_name"`
+ OsVersion string `json:"os_version"`
+ KernelVersion string `json:"kernel_version"`
+ IggyServerVersion string `json:"iggy_server_version"`
+ IggyServerSemver *uint32 `json:"iggy_server_semver,omitempty"`
+ CacheMetrics []CacheMetrics `json:"cache_metrics"`
+ ThreadsCount uint32 `json:"threads_count"`
+ FreeDiskSpace uint64 `json:"free_disk_space"`
+ TotalDiskSpace uint64 `json:"total_disk_space"`
+}
+
+func (cm *CacheMetrics) MarshalBinary() ([]byte, error) {
+ w := codec.NewWriterCap(32)
+ w.U32(cm.StreamId)
+ w.U32(cm.TopicId)
+ w.U32(cm.PartitionId)
+ w.U64(cm.Hits)
+ w.U64(cm.Misses)
+ w.F32(cm.HitRatio)
+ return w.Bytes(), w.Err()
+}
+
+func (cm *CacheMetrics) UnmarshalBinary(data []byte) error {
+ r := codec.NewReader(data)
+ cm.StreamId = r.U32()
+ cm.TopicId = r.U32()
+ cm.PartitionId = r.U32()
+ cm.Hits = r.U64()
+ cm.Misses = r.U64()
+ cm.HitRatio = r.F32()
+ return r.Err()
+}
+
+func (s *Stats) UnmarshalBinary(payload []byte) error {
+ r := codec.NewReader(payload)
+ s.ProcessId = r.U32()
+ s.CpuUsage = r.F32()
+ s.TotalCpuUsage = r.F32()
+ s.MemoryUsage = r.U64()
+ s.TotalMemory = r.U64()
+ s.AvailableMemory = r.U64()
+ s.RunTime = r.U64()
+ s.StartTime = r.U64()
+ s.ReadBytes = r.U64()
+ s.WrittenBytes = r.U64()
+ s.MessagesSizeBytes = r.U64()
+ s.StreamsCount = r.U32()
+ s.TopicsCount = r.U32()
+ s.PartitionsCount = r.U32()
+ s.SegmentsCount = r.U32()
+ s.MessagesCount = r.U64()
+ s.ClientsCount = r.U32()
+ s.ConsumerGroupsCount = r.U32()
+ s.Hostname = r.U32LenStr()
+ s.OsName = r.U32LenStr()
+ s.OsVersion = r.U32LenStr()
+ s.KernelVersion = r.U32LenStr()
+ s.IggyServerVersion = r.U32LenStr()
+
+ if r.Err() != nil {
+ return r.Err()
+ }
+
+ // iggy_server_semver is optional. If at least 8 bytes remain, the next
4
+ // bytes are the semver and the following 4 are cache_metrics_count.
+ // If only 4 bytes remain, there is no semver and those 4 bytes are
cache_metrics_count.
+ if r.Remaining() >= 8 {
+ v := r.U32()
+ s.IggyServerSemver = &v
+ }
+
+ cacheCount := int(r.U32())
+ if r.Err() != nil {
+ return r.Err()
+ }
+
+ if cacheCount > r.Remaining()/cacheMetricsWireSize {
+ return fmt.Errorf("stats: cache metrics count %d exceeds
remaining bytes %d", cacheCount, r.Remaining())
+ }
+
+ if cacheCount > 0 {
+ s.CacheMetrics = make([]CacheMetrics, cacheCount)
+ for i := range s.CacheMetrics {
+ r.Obj(cacheMetricsWireSize, &s.CacheMetrics[i])
+ }
+ }
+
+ if r.Err() == nil && r.Remaining() >= 4 {
Review Comment:
these 3 properties will always be there
--
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]