fix: fix test

This commit is contained in:
tonysken 2026-07-24 22:12:10 +01:00
parent bab0dfed81
commit 68e269ea7d
No known key found for this signature in database
GPG key ID: 67D2B9EB6131A6CE
4 changed files with 46 additions and 36 deletions

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"math"
"os"
"reflect"
"strconv"
"strings"
@ -49,19 +50,19 @@ import (
// }`
var PATHS_TO_CONVERT_BIGMETRICS = []map[string]string{
{"client_stats.cpu_stats.cpu_usage.total_usage": "nanoseconds"},
{"client_stats.cpu_stats.cpu_usage.percpu_usage": "nanoseconds"},
{"client_stats.cpu_stats.cpu_usage.usage_in_kernelmode": "nanoseconds"},
{"client_stats.cpu_stats.cpu_usage.usage_in_usermode": "nanoseconds"},
{"client_stats.cpu_stats.system_cpu_usage": "nanoseconds"},
{"client_stats.precpu_stats.cpu_usage.total_usage": "nanoseconds"},
{"client_stats.precpu_stats.cpu_usage.percpu_usage": "nanoseconds"},
{"client_stats.precpu_stats.cpu_usage.usage_in_kernelmode": "nanoseconds"},
{"client_stats.precpu_stats.cpu_usage.usage_in_usermode": "nanoseconds"},
{"client_stats.precpu_stats.system_cpu_usage": "nanoseconds"},
{"client_stats.memory_stats.limit": "bytes"},
{"client_stats.memory_stats.stats.hierarchical_memory_limit": "bytes"},
{"client_stats.memory_stats.stats.hierarchical_memsw_limit": "bytes"},
{"ClientStats.cpu_stats.cpu_usage.total_usage": "nanoseconds"},
{"ClientStats.cpu_stats.cpu_usage.percpu_usage": "nanoseconds"},
{"ClientStats.cpu_stats.cpu_usage.usage_in_kernelmode": "nanoseconds"},
{"ClientStats.cpu_stats.cpu_usage.usage_in_usermode": "nanoseconds"},
{"ClientStats.cpu_stats.system_cpu_usage": "nanoseconds"},
{"ClientStats.precpu_stats.cpu_usage.total_usage": "nanoseconds"},
{"ClientStats.precpu_stats.cpu_usage.percpu_usage": "nanoseconds"},
{"ClientStats.precpu_stats.cpu_usage.usage_in_kernelmode": "nanoseconds"},
{"ClientStats.precpu_stats.cpu_usage.usage_in_usermode": "nanoseconds"},
{"ClientStats.precpu_stats.system_cpu_usage": "nanoseconds"},
{"ClientStats.memory_stats.limit": "bytes"},
{"ClientStats.memory_stats.stats.hierarchical_memory_limit": "bytes"},
{"ClientStats.memory_stats.stats.hierarchical_memsw_limit": "bytes"},
}
func RenderStats(userConfig *config.UserConfig, container *commands.Container, viewWidth int) (string, error) {
@ -91,11 +92,19 @@ func RenderStats(userConfig *config.UserConfig, container *commands.Container, v
var statsMap map[string]interface{}
err = json.Unmarshal(statsJsonBytes, &statsMap)
b, _ := json.MarshalIndent(statsMap, "", " ")
_ = os.WriteFile("in.json", b, 0644)
if err != nil {
return "", err
}
convertBigMetricFromSchema(&statsMap)
// err = convertBigMetricFromSchema(&statsMap)
// b, _ = json.MarshalIndent(statsMap, "", " ")
// _ = os.WriteFile("out.json", b, 0644)
// if err != nil {
// _ = os.WriteFile("out", []byte(err.Error()), 0644)
// return "", err
// }
originalStats, err := utils.MarshalIntoYaml(statsMap)
if err != nil {
@ -111,6 +120,7 @@ func RenderStats(userConfig *config.UserConfig, container *commands.Container, v
)
return contents, nil
}
// plotGraph returns the plotted graph based on the graph spec and the stat history

View file

@ -18,14 +18,14 @@ func TestConvertBigMetricFromSchema(t *testing.T) {
{
name: "string schema: converts int64 bytes",
data: map[string]interface{}{
"client_stats": map[string]interface{}{
"ClientStats": map[string]interface{}{
"memory_stats": map[string]interface{}{
"limit": int64(2048),
},
},
},
expected: map[string]interface{}{
"client_stats": map[string]interface{}{
"ClientStats": map[string]interface{}{
"memory_stats": map[string]interface{}{
"limit": "2.000KB",
},
@ -35,7 +35,7 @@ func TestConvertBigMetricFromSchema(t *testing.T) {
{
name: "string schema: converts int64 nanoseconds",
data: map[string]interface{}{
"client_stats": map[string]interface{}{
"ClientStats": map[string]interface{}{
"cpu_stats": map[string]interface{}{
"cpu_usage": map[string]interface{}{
"total_usage": int64(100000000000),
@ -48,7 +48,7 @@ func TestConvertBigMetricFromSchema(t *testing.T) {
},
},
expected: map[string]interface{}{
"client_stats": map[string]interface{}{
"ClientStats": map[string]interface{}{
"cpu_stats": map[string]interface{}{
"cpu_usage": map[string]interface{}{
"total_usage": "100.000s",