mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
fix: fix test
This commit is contained in:
parent
bab0dfed81
commit
68e269ea7d
4 changed files with 46 additions and 36 deletions
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -49,19 +50,19 @@ import (
|
||||||
// }`
|
// }`
|
||||||
|
|
||||||
var PATHS_TO_CONVERT_BIGMETRICS = []map[string]string{
|
var PATHS_TO_CONVERT_BIGMETRICS = []map[string]string{
|
||||||
{"client_stats.cpu_stats.cpu_usage.total_usage": "nanoseconds"},
|
{"ClientStats.cpu_stats.cpu_usage.total_usage": "nanoseconds"},
|
||||||
{"client_stats.cpu_stats.cpu_usage.percpu_usage": "nanoseconds"},
|
{"ClientStats.cpu_stats.cpu_usage.percpu_usage": "nanoseconds"},
|
||||||
{"client_stats.cpu_stats.cpu_usage.usage_in_kernelmode": "nanoseconds"},
|
{"ClientStats.cpu_stats.cpu_usage.usage_in_kernelmode": "nanoseconds"},
|
||||||
{"client_stats.cpu_stats.cpu_usage.usage_in_usermode": "nanoseconds"},
|
{"ClientStats.cpu_stats.cpu_usage.usage_in_usermode": "nanoseconds"},
|
||||||
{"client_stats.cpu_stats.system_cpu_usage": "nanoseconds"},
|
{"ClientStats.cpu_stats.system_cpu_usage": "nanoseconds"},
|
||||||
{"client_stats.precpu_stats.cpu_usage.total_usage": "nanoseconds"},
|
{"ClientStats.precpu_stats.cpu_usage.total_usage": "nanoseconds"},
|
||||||
{"client_stats.precpu_stats.cpu_usage.percpu_usage": "nanoseconds"},
|
{"ClientStats.precpu_stats.cpu_usage.percpu_usage": "nanoseconds"},
|
||||||
{"client_stats.precpu_stats.cpu_usage.usage_in_kernelmode": "nanoseconds"},
|
{"ClientStats.precpu_stats.cpu_usage.usage_in_kernelmode": "nanoseconds"},
|
||||||
{"client_stats.precpu_stats.cpu_usage.usage_in_usermode": "nanoseconds"},
|
{"ClientStats.precpu_stats.cpu_usage.usage_in_usermode": "nanoseconds"},
|
||||||
{"client_stats.precpu_stats.system_cpu_usage": "nanoseconds"},
|
{"ClientStats.precpu_stats.system_cpu_usage": "nanoseconds"},
|
||||||
{"client_stats.memory_stats.limit": "bytes"},
|
{"ClientStats.memory_stats.limit": "bytes"},
|
||||||
{"client_stats.memory_stats.stats.hierarchical_memory_limit": "bytes"},
|
{"ClientStats.memory_stats.stats.hierarchical_memory_limit": "bytes"},
|
||||||
{"client_stats.memory_stats.stats.hierarchical_memsw_limit": "bytes"},
|
{"ClientStats.memory_stats.stats.hierarchical_memsw_limit": "bytes"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderStats(userConfig *config.UserConfig, container *commands.Container, viewWidth int) (string, error) {
|
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{}
|
var statsMap map[string]interface{}
|
||||||
err = json.Unmarshal(statsJsonBytes, &statsMap)
|
err = json.Unmarshal(statsJsonBytes, &statsMap)
|
||||||
|
b, _ := json.MarshalIndent(statsMap, "", " ")
|
||||||
|
_ = os.WriteFile("in.json", b, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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)
|
originalStats, err := utils.MarshalIntoYaml(statsMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -111,6 +120,7 @@ func RenderStats(userConfig *config.UserConfig, container *commands.Container, v
|
||||||
)
|
)
|
||||||
|
|
||||||
return contents, nil
|
return contents, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// plotGraph returns the plotted graph based on the graph spec and the stat history
|
// plotGraph returns the plotted graph based on the graph spec and the stat history
|
||||||
|
|
|
||||||
|
|
@ -18,16 +18,16 @@ func TestConvertBigMetricFromSchema(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "string schema: converts int64 bytes",
|
name: "string schema: converts int64 bytes",
|
||||||
data: map[string]interface{}{
|
data: map[string]interface{}{
|
||||||
"client_stats": map[string]interface{}{
|
"ClientStats": map[string]interface{}{
|
||||||
"memory_stats": map[string]interface{}{
|
"memory_stats": map[string]interface{}{
|
||||||
"limit": int64(2048),
|
"limit": int64(2048),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]interface{}{
|
||||||
"client_stats": map[string]interface{}{
|
"ClientStats": map[string]interface{}{
|
||||||
"memory_stats": map[string]interface{}{
|
"memory_stats": map[string]interface{}{
|
||||||
"limit": "2.000 KB",
|
"limit": "2.000KB",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -35,7 +35,7 @@ func TestConvertBigMetricFromSchema(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "string schema: converts int64 nanoseconds",
|
name: "string schema: converts int64 nanoseconds",
|
||||||
data: map[string]interface{}{
|
data: map[string]interface{}{
|
||||||
"client_stats": map[string]interface{}{
|
"ClientStats": map[string]interface{}{
|
||||||
"cpu_stats": map[string]interface{}{
|
"cpu_stats": map[string]interface{}{
|
||||||
"cpu_usage": map[string]interface{}{
|
"cpu_usage": map[string]interface{}{
|
||||||
"total_usage": int64(100000000000),
|
"total_usage": int64(100000000000),
|
||||||
|
|
@ -48,15 +48,15 @@ func TestConvertBigMetricFromSchema(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]interface{}{
|
expected: map[string]interface{}{
|
||||||
"client_stats": map[string]interface{}{
|
"ClientStats": map[string]interface{}{
|
||||||
"cpu_stats": map[string]interface{}{
|
"cpu_stats": map[string]interface{}{
|
||||||
"cpu_usage": map[string]interface{}{
|
"cpu_usage": map[string]interface{}{
|
||||||
"total_usage": "100.000 s",
|
"total_usage": "100.000s",
|
||||||
"percpu_usage": []string{"50.000 s", "50.000 s"},
|
"percpu_usage": []string{"50.000s", "50.000s"},
|
||||||
"usage_in_kernelmode": "200.000 µs",
|
"usage_in_kernelmode": "200.000µs",
|
||||||
"usage_in_usermode": "200.000 µs",
|
"usage_in_usermode": "200.000µs",
|
||||||
},
|
},
|
||||||
"system_cpu_usage": "100.000 s",
|
"system_cpu_usage": "100.000s",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -433,9 +433,9 @@ func FormatBigMetric(number int64, baseUnitName string) string {
|
||||||
}
|
}
|
||||||
switch baseUnitName {
|
switch baseUnitName {
|
||||||
case "bytes":
|
case "bytes":
|
||||||
return fmt.Sprintf("%.3f %s", float64(number)/float64(div), memoryUnits[exp-1])
|
return fmt.Sprintf("%.3f%s", float64(number)/float64(div), memoryUnits[exp-1])
|
||||||
case "nanoseconds":
|
case "nanoseconds":
|
||||||
return fmt.Sprintf("%.3f %s", float64(number)/float64(div), cpuUnits[exp-1])
|
return fmt.Sprintf("%.3f%s", float64(number)/float64(div), cpuUnits[exp-1])
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("%d", number)
|
return fmt.Sprintf("%d", number)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -505,25 +505,25 @@ func TestFormatBigMetric(t *testing.T) {
|
||||||
name: "bytes: KB",
|
name: "bytes: KB",
|
||||||
number: 1500,
|
number: 1500,
|
||||||
baseUnitName: "bytes",
|
baseUnitName: "bytes",
|
||||||
expected: "1.465 KB",
|
expected: "1.465KB",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bytes: MB",
|
name: "bytes: MB",
|
||||||
number: 1500000,
|
number: 1500000,
|
||||||
baseUnitName: "bytes",
|
baseUnitName: "bytes",
|
||||||
expected: "1.431 MB",
|
expected: "1.431MB",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bytes: GB",
|
name: "bytes: GB",
|
||||||
number: 1500000000,
|
number: 1500000000,
|
||||||
baseUnitName: "bytes",
|
baseUnitName: "bytes",
|
||||||
expected: "1.397 GB",
|
expected: "1.397GB",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bytes: TB",
|
name: "bytes: TB",
|
||||||
number: 1500000000000,
|
number: 1500000000000,
|
||||||
baseUnitName: "bytes",
|
baseUnitName: "bytes",
|
||||||
expected: "1.364 TB",
|
expected: "1.364TB",
|
||||||
},
|
},
|
||||||
// Nanoseconds tests
|
// Nanoseconds tests
|
||||||
{
|
{
|
||||||
|
|
@ -536,38 +536,38 @@ func TestFormatBigMetric(t *testing.T) {
|
||||||
name: "nanoseconds: µs",
|
name: "nanoseconds: µs",
|
||||||
number: 1500,
|
number: 1500,
|
||||||
baseUnitName: "nanoseconds",
|
baseUnitName: "nanoseconds",
|
||||||
expected: "1.500 µs",
|
expected: "1.500µs",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nanoseconds: ms",
|
name: "nanoseconds: ms",
|
||||||
number: 1500000,
|
number: 1500000,
|
||||||
baseUnitName: "nanoseconds",
|
baseUnitName: "nanoseconds",
|
||||||
expected: "1.500 ms",
|
expected: "1.500ms",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nanoseconds: s",
|
name: "nanoseconds: s",
|
||||||
number: 1500000000,
|
number: 1500000000,
|
||||||
baseUnitName: "nanoseconds",
|
baseUnitName: "nanoseconds",
|
||||||
expected: "1.500 s",
|
expected: "1.500s",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nanoseconds: m",
|
name: "nanoseconds: m",
|
||||||
number: 1500000000000,
|
number: 1500000000000,
|
||||||
baseUnitName: "nanoseconds",
|
baseUnitName: "nanoseconds",
|
||||||
expected: "1.500 m",
|
expected: "1.500m",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nanoseconds: h",
|
name: "nanoseconds: h",
|
||||||
number: 1500000000000000,
|
number: 1500000000000000,
|
||||||
baseUnitName: "nanoseconds",
|
baseUnitName: "nanoseconds",
|
||||||
expected: "1.500 h",
|
expected: "1.500h",
|
||||||
},
|
},
|
||||||
// Exact boundaries
|
// Exact boundaries
|
||||||
{
|
{
|
||||||
name: "bytes: exact 1024",
|
name: "bytes: exact 1024",
|
||||||
number: 1024,
|
number: 1024,
|
||||||
baseUnitName: "bytes",
|
baseUnitName: "bytes",
|
||||||
expected: "1.000 KB",
|
expected: "1.000KB",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bytes: 1023",
|
name: "bytes: 1023",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue