Skip to content

Commit

Permalink
Fix polling node when it is not ready and monitor by hostname (#22666)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel authored Dec 1, 2020
1 parent 5038ccf commit 09008c8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Added Kafka version 2.2 to the list of supported versions. {pull}22328[22328]
- Add support for ephemeral containers in kubernetes autodiscover and `add_kubernetes_metadata`. {pull}22389[22389] {pull}22439[22439]
- Added support for wildcard fields and keyword fallback in beats setup commands. {pull}22521[22521]
- Fix polling node when it is not ready and monitor by hostname {pull}22666[22666]

*Auditbeat*

Expand Down
11 changes: 11 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ func (n *node) emit(node *kubernetes.Node, flag string) {
return
}

// If the node is not in ready state then dont monitor it unless its a stop event
if !isNodeReady(node) && flag != "stop" {
return
}

eventID := fmt.Sprint(node.GetObjectMeta().GetUID())
meta := n.metagen.Generate(node)

Expand Down Expand Up @@ -237,6 +242,12 @@ func getAddress(node *kubernetes.Node) string {
}
}

for _, address := range node.Status.Addresses {
if address.Type == v1.NodeHostName && address.Address != "" {
return address.Address
}
}

return ""
}

Expand Down
59 changes: 58 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ func TestEmitEvent_Node(t *testing.T) {
Address: "node1",
},
},
Conditions: []v1.NodeCondition{
{
Type: v1.NodeReady,
Status: v1.ConditionTrue,
},
},
},
},
Expected: bus.Event{
Expand Down Expand Up @@ -183,6 +189,57 @@ func TestEmitEvent_Node(t *testing.T) {
"config": []*common.Config{},
},
},
{
Message: "Test node start with just node name",
Flag: "start",
Node: &kubernetes.Node{
ObjectMeta: metav1.ObjectMeta{
Name: name,
UID: types.UID(uid),
Labels: map[string]string{},
Annotations: map[string]string{},
},
TypeMeta: typeMeta,
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{
Type: v1.NodeHostName,
Address: "node1",
},
},
Conditions: []v1.NodeCondition{
{
Type: v1.NodeReady,
Status: v1.ConditionTrue,
},
},
},
},
Expected: bus.Event{
"start": true,
"host": "node1",
"id": uid,
"provider": UUID,
"kubernetes": common.MapStr{
"node": common.MapStr{
"name": "metricbeat",
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
"hostname": "node1",
},
"annotations": common.MapStr{},
},
"meta": common.MapStr{
"kubernetes": common.MapStr{
"node": common.MapStr{
"name": "metricbeat",
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
"hostname": "node1",
},
},
},
"config": []*common.Config{},
},
},
{
Message: "Test service without host",
Flag: "start",
Expand Down Expand Up @@ -221,7 +278,7 @@ func TestEmitEvent_Node(t *testing.T) {
},
Expected: bus.Event{
"stop": true,
"host": "",
"host": "node1",
"id": uid,
"provider": UUID,
"kubernetes": common.MapStr{
Expand Down

0 comments on commit 09008c8

Please sign in to comment.