Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/kubernetes-static: fixes and improvements (#148)
* cmd/kubernetes-static/readme.md: remove trailing whitespace Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/readme.md: fix documentation Right now the binary actually expect working directory to be root of the repository. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * go.mod: bump Go version to 1.16 To indicate that Go 1.16 should be used for building, so we can safely use go:embed directive for kubernetes-static. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/data: fix location of api-server metrics Integration expects it at "api-server" while it was at "apiserver". Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: print newline at the end of execution So when running shell do not spawn at the end of the output. That improves readability and usability, while it shouldn't interrupt any consumers, as usually trailing whitespace is properly handled. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/metric: automatically improve formatting Using 'gci' formatter. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static: use go:embed for serving static data This way, binary is independent from host file system and it's only important during build. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: simplify service list initialization Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: simplify mock client initialization In majority of cases there is no need to use 'new' keyword. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: simplify returned endpoint address There is no need to use 'localhost' explicitly. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: remove unnecessary Sleep Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: improve imports naming Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static: use only single source file So it's more intuitive to use 'go run'. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: add missing Service objects Part of #149 Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: fix collecting API server metrics Without this patch, following error is printed: "entity name and type are required when defining one" Part of #149 Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: use constants for controlplane components So they are less likely to get out of sync with other parts of the code. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/definition: improve variable names a bit Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/metric/definition.go: mark some metrics as optional Those metric may not always be available due to various reasons, marking them as optional silents them from reporting as errors. If I recall correctly: - createdAt, createdKind, createdBy, deploymentName metrics won't be available for e.g. static pods. - reason, message metrics will only be available for failing pods. - cpuRequestedCores, cpuLimitCores, memoryRequestedBytes, memoryLimitBytes will only be calculated for pods with resource requests configured. - pvc* metrics will only be available for volumes backed by actual PVC, not for EmptyDir volume etc. Refs #149 Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/definition/fetch.go: improve error messages a bit Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * cmd/kubernetes-static/main.go: mock newer Kubernetes version To at least align with version of latest test data we have. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/definition/populate.go: improve error message formatting Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/ksm/group.go: improve errors a bit To use standard formatting and some minimal error annotation to make error tracing easier while debugging. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/ksm/group.go: small styling improvements Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/kubelet: small styling improvements Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/kubelet/metric/metric.go: simplify loop logic Loop labels are not really needed, as they always stop the closest loop anyway. Check for nil Containers slice is also not needed, since iterating over nil slice will result in no iterations anyway. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/prometheus: small styling improvements Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/prometheus: improve error messages So it's clear which is label name and metric name. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> Co-authored-by: Roberto Santalla <roobre@roobre.es> * src/metric/definition.go: improve error messages in toUtilization() Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/definition: small styling and formatting improvements Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * src/kubelet/metric: improvements to GetMetricsData method It will now return a pointer to a summary, which should save some memory copying and is more standard approach for functions, which may return error in Go. Additionally, to make use of using structure pointer, GroupStatsSummary() method is also adopted to take a pointer of the summary. There are also improved error messages in GetMetricsData(), which should be more helpful while debugging. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> Co-authored-by: Roberto Santalla <roobre@roobre.es>
- Loading branch information