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

Add Kubernetes StatefulSet metricset #6236

Merged
merged 9 commits into from
Feb 2, 2018

Conversation

fassisrosa
Copy link
Contributor

Added support for Kubernetes StatefulSet.

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@@ -0,0 +1,111 @@
// +build !integration

package state_statefulset

Choose a reason for hiding this comment

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

don't use an underscore in package name

@@ -0,0 +1,62 @@
package state_statefulset

Choose a reason for hiding this comment

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

don't use an underscore in package name

continue
}
namespace := util.GetLabel(metric, "namespace")
statefulset_key := namespace + "::" + statefulset

Choose a reason for hiding this comment

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

don't use underscores in Go names; var statefulset_key should be statefulsetKey

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the bot comment is valid here 😇

Now I see this, it seems the rest of state_* may miss the namespacing you did here, I'm glad you found this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to mention it after this pull request. Worth fixing others no doubt. :)

@@ -0,0 +1,52 @@
package state_statefulset

Choose a reason for hiding this comment

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

don't use an underscore in package name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following same pattern as other classes.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, please ignore the bot on this.

@fassisrosa
Copy link
Contributor Author

Added unit testing for StatefulSet support. Made StatefulSet be relative to namespace (i.e. you can have two statefulsets with same name belonging to different namespaces).

@fassisrosa
Copy link
Contributor Author

I signed CLA already.

@ruflin
Copy link
Contributor

ruflin commented Jan 31, 2018

@fassisrosa Thanks for you contribution. Haven't look at the code yet but it for sure will need an entry in the CHANGELOG :-)

@fassisrosa
Copy link
Contributor Author

Added entry to CHANGELOG.

Copy link
Contributor

@exekias exekias left a comment

Choose a reason for hiding this comment

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

Awesome contribution, thank you @fassisrosa 🎉, StatefulSets are a great addition! I left some minor comments 😄

continue
}
namespace := util.GetLabel(metric, "namespace")
statefulset_key := namespace + "::" + statefulset
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the bot comment is valid here 😇

Now I see this, it seems the rest of state_* may miss the namespacing you did here, I'm glad you found this!

// Part of new is also setting up the configuration by processing additional
// configuration entries if needed.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
cfgwarn.Beta("The kubernetes state_statefulset metricset is beta")
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this message, kubernetes module has been promoted to GA

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed bot comment.

@exekias
Copy link
Contributor

exekias commented Jan 31, 2018

jenkins, test it please

}

if len(testCases) > 0 {
t.Error("Test reference events not found: %v", testCases)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be Errorf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@exekias exekias changed the title Kubernetes metrics Add Kubernetes StatefulSet metricset Jan 31, 2018
}
}

var events []common.MapStr
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you could pre allocate events by events := make([]common.MapStr, 0, len(eventsMap))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@fassisrosa
Copy link
Contributor Author

Any idea what this Travis CI build fail is all about? Looks like a code convention violation but have no idea about the test’s expectations...

@walktall
Copy link
Contributor

walktall commented Feb 1, 2018

@fassisrosa You should obey the the go import style. First section with std pkgs, second is community pkgs such as github.com, third section is project pkg in this case is pkg under beats project.

@fassisrosa
Copy link
Contributor Author

fassisrosa commented Feb 1, 2018

Understood, I think... but then how did state_replicaset_test.go pass checks? Tried to follow same convention.

Just to confirm, issue is in state_statefulset_test.go imports should be in correct order:

 "net/http"
 "net/http/httptest"
 "os"
 "testing"

 "github.com/stretchr/testify/assert"

 "github.com/elastic/beats/libbeat/common"
 mbtest "github.com/elastic/beats/metricbeat/mb/testing"

Is this the correct fix?

Thanks for your patience, this is my first commit to beats, trying to understand the rules for submissions :)

@exekias
Copy link
Contributor

exekias commented Feb 1, 2018

That looks correct, you can use make fmt to automatically fix formatting

@fassisrosa
Copy link
Contributor Author

Thanks @exekias , made changes, ran fmt, pushed.

Copy link
Contributor

@exekias exekias left a comment

Choose a reason for hiding this comment

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

Waiting for green

@exekias
Copy link
Contributor

exekias commented Feb 1, 2018

ok to test

func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return &MetricSet{
BaseMetricSet: base,
prometheus: helper.NewPrometheusClient(base),
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is failing in the CI, NewPrometheusClient can return an error

Copy link
Contributor

Choose a reason for hiding this comment

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

To put some context, this changed very recently: #6205, probably your working copy doesn't have the change

@exekias exekias merged commit 4cbb1de into elastic:master Feb 2, 2018
@exekias
Copy link
Contributor

exekias commented Feb 2, 2018

Thank you so much for this great addition @fassisrosa 🎉!!

@fassisrosa
Copy link
Contributor Author

Thanks so much for the review comments. Love metricbeat, using it all the time! :)

@exekias
Copy link
Contributor

exekias commented Feb 5, 2018

I've opened #6281 to fix the namespacing issue in the rest of state_ metricsets, plan to take it next week, let me know if you want to take a stab at it 😸

@fassisrosa
Copy link
Contributor Author

Taking a stab at it... Pull request above. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants