Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/kubernetes-static: fixes and improvements #148

Merged
merged 30 commits into from
Jul 16, 2021
Merged

Conversation

invidian
Copy link
Contributor

@invidian invidian commented Jul 9, 2021

No description provided.

src/definition/fetch_test.go Show resolved Hide resolved
src/definition/fetch_test.go Show resolved Hide resolved
src/kubelet/metric/metric.go Outdated Show resolved Hide resolved
src/kubelet/metric/metric.go Show resolved Hide resolved
src/kubelet/metric/metric.go Show resolved Hide resolved
src/metric/populate_test.go Show resolved Hide resolved
src/prometheus/definition.go Outdated Show resolved Hide resolved
src/prometheus/definition.go Outdated Show resolved Hide resolved
src/prometheus/definition.go Outdated Show resolved Hide resolved
@invidian invidian force-pushed the invidian/improvements branch 2 times, most recently from 95269ca to 21d1242 Compare July 14, 2021 17:35
@invidian invidian requested a review from roobre July 14, 2021 17:41
cmd/kubernetes-static/main.go Outdated Show resolved Hide resolved
cmd/kubernetes-static/readme.md Outdated Show resolved Hide resolved
src/ksm/group.go Outdated Show resolved Hide resolved
src/kubelet/metric/metric.go Outdated Show resolved Hide resolved
src/kubelet/metric/metric.go Outdated Show resolved Hide resolved
src/kubelet/metric/metric.go Outdated Show resolved Hide resolved
Copy link
Contributor

@gsanchezgavier gsanchezgavier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

cmd/kubernetes-static/main.go Show resolved Hide resolved
@@ -192,7 +191,11 @@ func fetchVolumeStats(v v1.VolumeStats) (definition.RawMetrics, error) {
}

// GroupStatsSummary groups specific data for pods, containers and node
func GroupStatsSummary(statsSummary v1.Summary) (definition.RawGroups, []error) {
func GroupStatsSummary(statsSummary *v1.Summary) (definition.RawGroups, []error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes me think that statsSummary is going to be modified inside the function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ Rob Pike pls add const to go asap thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ Rob Pike pls add const to go asap thanks

I subscribed to golang/go#22876 just yesterday 😄 I think Rust does a good job with mutable ref here.

this makes me think that statsSummary is going to be modified inside the function.

@gsanchezgavier I understand your concern. However, as far as I know, most of the time you should expect that function will not modify it's parameters, but rather return a mutated copy of the data. Modifying in place is a performance optimization IMO.

Given that this function returns a different format, I think it should be obvious to assume the summary won't be modified.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Right now the binary actually expect working directory to be root of the
repository.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
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>
Integration expects it at "api-server" while it was at "apiserver".

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
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>
Using 'gci' formatter.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
This way, binary is independent from host file system and it's only
important during build.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
In majority of cases there is no need to use 'new' keyword.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
There is no need to use 'localhost' explicitly.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
So it's more intuitive to use 'go run'.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Part of #149

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
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>
So they are less likely to get out of sync with other parts of the code.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
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>
invidian and others added 11 commits July 16, 2021 17:55
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
To at least align with version of latest test data we have.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
To use standard formatting and some minimal error annotation to make
error tracing easier while debugging.

Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
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>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
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>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
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>
Copy link
Contributor

@roobre roobre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks and killer work @invidian !

@roobre roobre merged commit 5f2ad02 into main Jul 16, 2021
@roobre roobre deleted the invidian/improvements branch July 16, 2021 16:17
roobre added a commit that referenced this pull request Jul 16, 2021
These errors are no longer returned and they were rebased-in by mistake.
@roobre roobre mentioned this pull request Jul 16, 2021
roobre added a commit that referenced this pull request Jul 19, 2021
These errors are no longer returned and they were rebased-in by mistake.
roobre added a commit that referenced this pull request Jul 20, 2021
These errors are no longer returned and they were rebased-in by mistake.
roobre added a commit that referenced this pull request Jul 20, 2021
These errors are no longer returned and they were rebased-in by mistake.
roobre added a commit that referenced this pull request Jul 23, 2021
These errors are no longer returned and they were rebased-in by mistake.
roobre added a commit that referenced this pull request Jul 27, 2021
These errors are no longer returned and they were rebased-in by mistake.
roobre added a commit that referenced this pull request Jul 28, 2021
These errors are no longer returned and they were rebased-in by mistake.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants