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 events metricset for kubernetes metricbeat module #4315

Merged
merged 3 commits into from
May 18, 2017

Conversation

vjsamuel
Copy link
Contributor

@vjsamuel vjsamuel commented May 15, 2017

This PR adds a kubernetes events metricset to the kubernetes metricbeat module. Events are polled from the kubernetes API server and are written into the outputs interface.

@vjsamuel vjsamuel changed the title Adding events metricset for kubernetes metricbeat module WIP: Adding events metricset for kubernetes metricbeat module May 15, 2017
@vjsamuel
Copy link
Contributor Author

@ruflin, vendoring needs to be decided as im getting these info messages:

2017/05/15 01:06:58 proto: duplicate proto type registered: github.com/ericchiang.k8s.apis.extensions.v1beta1.DaemonSetList
2017/05/15 01:06:58 proto: duplicate proto type registered: github.com/ericchiang.k8s.apis.extensions.v1beta1.DaemonSetSpec
2017/05/15 01:06:58 proto: duplicate proto type registered: github.com/ericchiang.k8s.apis.extensions.v1beta1.DaemonSetStatus
2017/05/15 01:06:58 proto: duplicate proto type registered: github.com/ericchiang.k8s.apis.extensions.v1beta1.DaemonSetUpdateStrategy
2017/05/15 01:06:58 proto: duplicate proto type registered: github.com/ericchiang.k8s.apis.extensions.v1beta1.Deployment

@elasticmachine
Copy link
Collaborator

Jenkins standing by to test this. If you aren't a maintainer, you can ignore this comment. Someone with commit access, please review this and clear it for Jenkins to run.

1 similar comment
@elasticmachine
Copy link
Collaborator

Jenkins standing by to test this. If you aren't a maintainer, you can ignore this comment. Someone with commit access, please review this and clear it for Jenkins to run.

@monicasarbu monicasarbu added in progress Pull request is currently in progress. Metricbeat Metricbeat labels May 15, 2017
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM, did a quick scan of the metricset implementation only.

// Part of new is also setting up the configuration by processing additional
// configuration entries if needed.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
logp.Warn("EXPERIMENTAL: The kubernetes events metricset is experimental")
Copy link
Member

Choose a reason for hiding this comment

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

Use logp.Experimental.

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. We would need to update the metricset generator as this was generated code.

return nil, fmt.Errorf("fail to unpack the kubernetes events configuration: %s", err)
}

err = validate(config)
Copy link
Member

Choose a reason for hiding this comment

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

go-ucfg allows a config type to implement a Validate() error function that is invoked automatically on when unpacking.

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.

m.watcher.Stop()
return
case msg := <-m.watcher.eventQueue:
// Ignore events that are deleted
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you ignoring deletion events? I guess someone could be interested on them, perhaps we should offer some fine grained filter for desired events?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

delete, in case of events is to just delete the API Event object. it carries no significance from monitoring perspective.

@vjsamuel vjsamuel changed the title WIP: Adding events metricset for kubernetes metricbeat module Add events metricset for kubernetes metricbeat module May 15, 2017
@vjsamuel vjsamuel force-pushed the kubernetes_events branch 2 times, most recently from 2e53faf to c87167f Compare May 15, 2017 19:36
Copy link
Contributor

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I left a few comments mainly related to naming conventions.

One thing that seems to be missing is adding it to the config file.

From which of the two services which we connect to in the kubernetes module at the moment will this info be fetched? What is the installation pattern?

@@ -6040,6 +6040,194 @@ Used inodes


[float]
== events Fields
Copy link
Contributor

Choose a reason for hiding this comment

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

The metricset should probably be called event and not events to be in line with our naming convention.



[float]
=== kubernetes.events.firstOccurrenceTimestamp
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to change this to *.event.timestamp.first_occurenceand below to *.event.timestamp.last_occurence.



[float]
=== kubernetes.events.metadata.creationTimestamp
Copy link
Contributor

Choose a reason for hiding this comment

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

timestamp.created, timestamp.deleted



[float]
=== kubernetes.events.metadata.resourceVersion
Copy link
Contributor

Choose a reason for hiding this comment

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

resource_version or version.resource



[float]
=== kubernetes.events.metadata.selfLink
Copy link
Contributor

Choose a reason for hiding this comment

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

self_link



[float]
=== kubernetes.events.tags.host
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this under tags



[float]
=== kubernetes.events.tags.pod
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this under tags. Don't we have a common namespace for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are dimensions that can be used to better query information. base implementation off of which I went with is here:
https://github.com/kubernetes/heapster/blob/master/events/sinks/elasticsearch/driver.go#L76

)

// EventWatcher is a controller that synchronizes Pods.
type EventWatcher struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could call this just Watcher as it is already in the event package.

if err != nil {
//if listing fails try again after sometime
logp.Err("kubernetes: List API error %v", err)
time.Sleep(time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on what did you select this timeout? Perhaps a comment could be helpful here.

//watch events failures should be logged and gracefully failed over as metadata retrieval
//should never stop.
logp.Err("kubernetes: Watching API eror %v", err)
time.Sleep(time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

@vjsamuel vjsamuel force-pushed the kubernetes_events branch from c87167f to 463299c Compare May 16, 2017 17:52
- module: kubernetes
metricsets:
- event
kube_config: ${HOME}/.kube/config
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Is ${HOME} always set in these environments?
  • You left out the hosts: [...] part. Is that on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as per @exekias we can default in_cluster to true. this metricset doesnt rely on hosts by default. we can add documentation on various ways to configure it similar to the kubernetes processor.

},
"message": "Created pod: prometheus-2552087900-9fxh6",
"metadata": {
"annotations": null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to not send fields if they are null

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

# Kubernetes events
- module: kubernetes
metricsets:
- event
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember @exekias added somewhere that all state_* prefixed metricset must be installed once in contrast to the other ones. If this is installed global (my assumption) should this also have a state_ prefix?

NOTE: In general I think we need to find a better solution for this in the long run but in the short term we should try to be consistent.

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 event (or events) is ok in this case, this is something unrelated to kube-state-metrics, state_ metricsets get their name from it

metricsets:
- event
kube_config: ${HOME}/.kube/config
in_cluster: false
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps we should leave in_cluster: true as default? I guess it will be the most common case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will default to true

# Kubernetes events
- module: kubernetes
metricsets:
- event
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 event (or events) is ok in this case, this is something unrelated to kube-state-metrics, state_ metricsets get their name from it

"deleted": eve.Metadata.DeletionTimestamp,
},
"name": eve.Metadata.Name,
"namespace": eve.Metadata.Namespace,
Copy link
Contributor

Choose a reason for hiding this comment

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

this one can ve moved to kubernetes.namespace, using mb.ModuleKey. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we would need to do this across all metricsets to establish consistency. lets do it in a follow-up PR all in one go.

@vjsamuel vjsamuel force-pushed the kubernetes_events branch from 463299c to a5e3f48 Compare May 17, 2017 16:50
@vjsamuel vjsamuel force-pushed the kubernetes_events branch from a5e3f48 to 3267969 Compare May 18, 2017 06:23
@ruflin
Copy link
Contributor

ruflin commented May 18, 2017

jenkins, test it

SyncPeriod time.Duration `config:"sync_period"`
}

type Enabled struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type Enabled should have comment or be unexported

Enabled bool `config:"enabled"`
}

type PluginConfig []map[string]common.Config
Copy link
Collaborator

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type PluginConfig should have comment or be unexported


import "time"

type ObjectMeta struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type ObjectMeta should have comment or be unexported

UID string `json:"uid"`
}

type Event struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type Event should have comment or be unexported


}

func (w *Watcher) Run() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method Watcher.Run should have comment or be unexported


}

func (w *Watcher) Stop() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method Watcher.Stop should have comment or be unexported

@exekias exekias merged commit cc0f165 into elastic:master May 18, 2017
@exekias exekias mentioned this pull request May 18, 2017
3 tasks
@monicasarbu monicasarbu added review and removed in progress Pull request is currently in progress. labels May 23, 2017
@vjsamuel vjsamuel deleted the kubernetes_events branch March 5, 2018 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants