From f75512f990d6e93461c4238ab949ade82edb770a Mon Sep 17 00:00:00 2001 From: barnett <576501057@qq.com> Date: Mon, 28 Jan 2019 17:13:38 +0800 Subject: [PATCH] [FIX] fix cpu unit error bug --- api/handler/tenant.go | 2 +- worker/appm/store/store.go | 20 ++++++++++---------- worker/server/server.go | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/api/handler/tenant.go b/api/handler/tenant.go index f90d3a5157..1538576f63 100644 --- a/api/handler/tenant.go +++ b/api/handler/tenant.go @@ -197,7 +197,7 @@ func (t *TenantAction) GetTenantsResources(tr *api_model.TenantResources) (map[s "service_running_num": tr.RunningAppNum, "service_total_num": serviceTenantCount[tenantID], "cpu": tr.CpuRequest, - "memory": tr.MemoryRequest / 1024 / 1024, + "memory": tr.MemoryRequest, "disk": 0, } } diff --git a/worker/appm/store/store.go b/worker/appm/store/store.go index 45215b6039..a70d2b8d83 100644 --- a/worker/appm/store/store.go +++ b/worker/appm/store/store.go @@ -704,23 +704,23 @@ func (a *appRuntimeStore) GetTenantResource(tenantID string) *v1.TenantResource cpurequest := container.Resources.Requests.Cpu() memoryrequest := container.Resources.Requests.Memory() if cpulimit != nil { - if cpulimit, ok := cpulimit.AsInt64(); ok { - resource.CPULimit += cpulimit - } + resource.CPULimit += cpulimit.MilliValue() } if memorylimit != nil { - if memorylimit, ok := memorylimit.AsInt64(); ok { - resource.MemoryLimit += memorylimit + if ml, ok := memorylimit.AsInt64(); ok { + resource.MemoryLimit += ml + } else { + resource.MemoryLimit += memorylimit.Value() } } if cpurequest != nil { - if cpurequest, ok := cpurequest.AsInt64(); ok { - resource.CPURequest += cpurequest - } + resource.CPURequest += cpurequest.MilliValue() } if memoryrequest != nil { - if memoryrequest, ok := memoryrequest.AsInt64(); ok { - resource.MemoryRequest += memoryrequest + if mr, ok := memoryrequest.AsInt64(); ok { + resource.MemoryRequest += mr + } else { + resource.MemoryRequest += memoryrequest.Value() } } } diff --git a/worker/server/server.go b/worker/server/server.go index ce49f7638a..0ddd46d34d 100644 --- a/worker/server/server.go +++ b/worker/server/server.go @@ -101,8 +101,8 @@ func (r *RuntimeServer) GetTenantResource(ctx context.Context, re *pb.TenantRequ return &tr, nil } tr.RunningAppNum = int64(len(r.store.GetTenantRunningApp(re.TenantId))) - tr.CpuLimit = res.CPULimit - tr.CpuRequest = res.CPURequest + tr.CpuLimit = res.CPULimit * 1000 + tr.CpuRequest = res.CPURequest * 1000 tr.MemoryLimit = res.MemoryLimit / 1024 / 1024 tr.MemoryRequest = res.MemoryRequest / 1024 / 1024 return &tr, nil