Skip to content

Commit

Permalink
feat(server): Pod view metrics (#5090)
Browse files Browse the repository at this point in the history
Signed-off-by: Remington Breeze <remington@breeze.software>
  • Loading branch information
rbreeze authored Dec 18, 2020
1 parent e1075bf commit 1d672e7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
20 changes: 17 additions & 3 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,11 @@
"ApplicationService"
],
"summary": "ListNodes returns nodes associated with an application",
"operationId": "ListNodes",
"operationId": "ApplicationService_ListNodes",
"parameters": [
{
"type": "string",
"description": "get nodes associated with this application",
"description": "the application's name",
"name": "name",
"in": "path",
"required": true
Expand All @@ -710,6 +710,12 @@
"schema": {
"$ref": "#/definitions/v1NodeList"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/runtimeError"
}
}
}
}
Expand Down Expand Up @@ -3798,6 +3804,15 @@
"repositoryRepoResponse": {
"type": "object"
},
"resourceQuantity": {
"description": "Quantity is a fixed-point representation of a number.\nIt provides convenient marshaling/unmarshaling in JSON and YAML,\nin addition to String() and AsInt64() accessors.\n\nThe serialization format is:\n\n<quantity> ::= <signedNumber><suffix>\n (Note that <suffix> may be empty, from the \"\" case in <decimalSI>.)\n<digit> ::= 0 | 1 | ... | 9\n<digits> ::= <digit> | <digit><digits>\n<number> ::= <digits> | <digits>.<digits> | <digits>. | .<digits>\n<sign> ::= \"+\" | \"-\"\n<signedNumber> ::= <number> | <sign><number>\n<suffix> ::= <binarySI> | <decimalExponent> | <decimalSI>\n<binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei\n (International System of units; See: http://physics.nist.gov/cuu/Units/binary.html)\n<decimalSI> ::= m | \"\" | k | M | G | T | P | E\n (Note that 1024 = 1Ki but 1000 = 1k; I didn't choose the capitalization.)\n<decimalExponent> ::= \"e\" <signedNumber> | \"E\" <signedNumber>\n\nNo matter which of the three exponent forms is used, no quantity may represent\na number greater than 2^63-1 in magnitude, nor may it have more than 3 decimal\nplaces. Numbers larger or more precise will be capped or rounded up.\n(E.g.: 0.1m will rounded up to 1m.)\nThis may be extended in the future if we require larger or smaller quantities.\n\nWhen a Quantity is parsed from a string, it will remember the type of suffix\nit had, and will use the same type again when it is serialized.\n\nBefore serializing, Quantity will be put in \"canonical form\".\nThis means that Exponent/suffix will be adjusted up or down (with a\ncorresponding increase or decrease in Mantissa) such that:\n a. No precision is lost\n b. No fractional digits will be emitted\n c. The exponent (or suffix) is as large as possible.\nThe sign will be omitted unless the number is negative.\n\nExamples:\n 1.5 will be serialized as \"1500m\"\n 1.5Gi will be serialized as \"1536Mi\"\n\nNote that the quantity will NEVER be internally represented by a\nfloating point number. That is the whole point of this exercise.\n\nNon-canonical values will still parse as long as they are well formed,\nbut will be re-emitted in their canonical form. (So always use canonical\nform, or don't diff.)\n\nThis format is intended to make it difficult to use these numbers without\nwriting some sort of special handling code in the hopes that that will\ncause implementors to also use a fixed point implementation.\n\n+protobuf=true\n+protobuf.embed=string\n+protobuf.options.marshal=false\n+protobuf.options.(gogoproto.goproto_stringer)=false\n+k8s:deepcopy-gen=true\n+k8s:openapi-gen=true",
"type": "object",
"properties": {
"string": {
"type": "string"
}
}
},
"runtimeError": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -4311,7 +4326,6 @@
},
"unschedulable": {
"type": "boolean",
"format": "boolean",
"title": "Unschedulable controls node schedulability of new pods. By default, node is schedulable.\nMore info: https://kubernetes.io/docs/concepts/nodes/node/#manual-node-administration\n+optional"
}
}
Expand Down
11 changes: 11 additions & 0 deletions controller/cache/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
resourcehelper "k8s.io/kubernetes/pkg/api/v1/resource"
k8snode "k8s.io/kubernetes/pkg/util/node"

"github.com/argoproj/argo-cd/common"
Expand Down Expand Up @@ -311,7 +312,17 @@ func populatePodInfo(un *unstructured.Unstructured, res *ResourceInfo) {
if reason != "" {
res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Status Reason", Value: reason})
}

req, limit := resourcehelper.PodRequestsAndLimits(&pod)
cpuReq, cpuLimit, memoryReq, memoryLimit := req[v1.ResourceCPU], limit[v1.ResourceCPU], req[v1.ResourceMemory], limit[v1.ResourceMemory]

res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Node", Value: fmt.Sprintf("%s", pod.Spec.NodeName)})

res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Resource.CpuReq", Value: fmt.Sprintf("%d", cpuReq.MilliValue())})
res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Resource.CpuLimit", Value: fmt.Sprintf("%d", cpuLimit.MilliValue())})
res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Resource.MemoryReq", Value: fmt.Sprintf("%d", memoryReq.Value())})
res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Resource.MemoryLimit", Value: fmt.Sprintf("%d", memoryLimit.Value())})

res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Containers", Value: fmt.Sprintf("%d/%d", readyContainers, totalContainers)})
res.NetworkingInfo = &v1alpha1.ResourceNetworkingInfo{Labels: un.GetLabels()}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ require (
k8s.io/klog/v2 v2.3.0 // indirect
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6
k8s.io/kubectl v0.19.2
k8s.io/kubernetes v1.19.2
k8s.io/kubernetes v1.19.3
k8s.io/utils v0.0.0-20200729134348-d5654de09c73
layeh.com/gopher-json v0.0.0-20190114024228-97fed8db8427
sigs.k8s.io/yaml v1.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ k8s.io/kubectl v0.19.2/go.mod h1:4ib3oj5ma6gF95QukTvC7ZBMxp60+UEAhDPjLuBIrV4=
k8s.io/kubelet v0.19.2/go.mod h1:FHHoByVWzh6kNaarXaDPAa751Oz6REcOVRyFT84L1Is=
k8s.io/kubernetes v1.19.2 h1:sEvBYVM1/H5hqejFR10u8ndreYARV3DiTrqi2AY31ok=
k8s.io/kubernetes v1.19.2/go.mod h1:yhT1/ltQajQsha3tnYc9QPFYSumGM45nlZdjf7WqE1A=
k8s.io/kubernetes v1.19.3 h1:V6ohBHSxTkrPRyfVp8tbdEsgi9nfVN49xlUVkQseass=
k8s.io/kubernetes v1.19.3/go.mod h1:yhT1/ltQajQsha3tnYc9QPFYSumGM45nlZdjf7WqE1A=
k8s.io/legacy-cloud-providers v0.19.2/go.mod h1:++wIKZl+1DvQ5i5y1T2ZzwYRkLFuhsZ/SIEivHsM9ro=
k8s.io/metrics v0.19.2/go.mod h1:IlLaAGXN0q7yrtB+SV0q3JIraf6VtlDr+iuTcX21fCU=
k8s.io/sample-apiserver v0.19.2/go.mod h1:XZxHsGPvUkjzos8B/lhbM4REthLt4tRMfkhN2CRXCGs=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function renderResourceNode(props: ApplicationResourceTreeProps, id: string, nod
{node.createdAt || props.app.metadata.creationTimestamp}
</Moment>
) : null}
{(node.info || []).map((tag, i) => (
{(node.info || []).filter(tag => !tag.name.includes('Resource.')).map((tag, i) => (
<span className='application-resource-tree__node-label' title={`${tag.name}:${tag.value}`} key={i}>
{tag.value}
</span>
Expand Down

0 comments on commit 1d672e7

Please sign in to comment.