jaime 1d06d4324b
fix: Int64 overflow in JSON encoding (#37657)
issue: ##36621

- For simple types in a struct, add "string" to the JSON tag for
automatic string conversion during JSON encoding.
- For complex types in a struct, replace "int64" with "string."

Signed-off-by: jaime <yun.zhang@zilliz.com>
2024-11-14 22:52:30 +08:00

46 lines
1.4 KiB
Go

package metrics
import (
"strconv"
"github.com/samber/lo"
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
)
func NewSegmentFrom(segment *datapb.SegmentInfo) *metricsinfo.Segment {
return &metricsinfo.Segment{
SegmentID: segment.GetID(),
CollectionID: segment.GetCollectionID(),
PartitionID: segment.GetPartitionID(),
Channel: segment.GetInsertChannel(),
NumOfRows: segment.GetNumOfRows(),
State: segment.GetState().String(),
IsImporting: segment.GetIsImporting(),
Compacted: segment.GetCompacted(),
Level: segment.GetLevel().String(),
IsSorted: segment.GetIsSorted(),
IsInvisible: segment.GetIsInvisible(),
}
}
func NewDMChannelFrom(channel *datapb.VchannelInfo) *metricsinfo.DmChannel {
return &metricsinfo.DmChannel{
CollectionID: channel.GetCollectionID(),
ChannelName: channel.GetChannelName(),
UnflushedSegmentIds: lo.Map(channel.GetUnflushedSegmentIds(), func(t int64, i int) string {
return strconv.FormatInt(t, 10)
}),
FlushedSegmentIds: lo.Map(channel.GetFlushedSegmentIds(), func(t int64, i int) string {
return strconv.FormatInt(t, 10)
}),
DroppedSegmentIds: lo.Map(channel.GetDroppedSegmentIds(), func(t int64, i int) string {
return strconv.FormatInt(t, 10)
}),
LevelZeroSegmentIds: lo.Map(channel.GetLevelZeroSegmentIds(), func(t int64, i int) string {
return strconv.FormatInt(t, 10)
}),
}
}