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

Fix fields in kvm status metricset #18514

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -26873,6 +26873,26 @@ kvm module



*`kvm.id`*::
+
--
Domain id


type: long

--

*`kvm.name`*::
+
--
Domain name


type: keyword

--

[float]
=== kvm

Expand Down Expand Up @@ -26940,37 +26960,10 @@ status



[float]
=== stat

Memory stat



*`kvm.status.stat.state`*::
+
--
domain state


type: keyword

--

*`kvm.status.id`*::
*`kvm.status.state`*::
+
--
Domain id


type: long

--

*`kvm.status.name`*::
+
--
Domain name
Domain state


type: keyword
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/kvm/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
description: >
kvm module
fields:
- name: kvm.id
type: long
description: >
Domain id
- name: kvm.name
type: keyword
description: >
Domain name
- name: kvm
type: group
description: >
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/kvm/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 20 additions & 25 deletions metricbeat/module/kvm/status/_meta/data.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"agent": {
"hostname": "host.example.com",
"name": "host.example.com"
"event": {
"dataset": "kvm.status",
"duration": 115000,
"module": "kvm"
},
"event":{
"dataset":"kvm.status",
"module":"kvm",
"duration":4012216
},
"metricset":{
"name":"status"
},
"service":{
"address":"unix:///var/run/libvirt/libvirt-sock",
"type":"kvm"
},
"kvm":{
"status":{
"stat":{
"state":"running"
},
"id":1,
"name":"generic-2"
}
}
}
"kvm": {
"id": 1,
"name": "buster-amd64",
"status": {
"state": "running"
}
},
"metricset": {
"name": "status",
"period": 10000
},
"service": {
"address": "unix:///var/run/libvirt/libvirt-sock",
"type": "kvm"
}
}
21 changes: 4 additions & 17 deletions metricbeat/module/kvm/status/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,7 @@
status
release: beta
fields:
- name: stat
type: group
description: >
Memory stat
fields:
- name: state
type: keyword
description: >
domain state
- name: id
type: long
description: >
Domain id
- name: name
type: keyword
description: >
Domain name
- name: state
type: keyword
description: >
Domain state
4 changes: 1 addition & 3 deletions metricbeat/module/kvm/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error {
"name": d.Name,
},
MetricSetFields: common.MapStr{
"stat": common.MapStr{
"state": getDomainStateName(state),
},
"state": getDomainStateName(state),
},
})
if !reported {
Expand Down
47 changes: 47 additions & 0 deletions metricbeat/module/kvm/status/status_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package status

import (
"net"
"os/exec"
"testing"
"time"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
)

func TestData(t *testing.T) {
sockPath := "/var/run/libvirt/libvirt-sock"
checkLibvirt(t, sockPath)

f := mbtest.NewFetcher(t, getConfig("unix://"+sockPath))
f.WriteEvents(t, "")
}

func checkLibvirt(t *testing.T, sockPath string) {
if exec.Command("kvm-ok").Run() != nil {
t.Skip("kvm not available")
}

c, err := net.DialTimeout("unix", sockPath, 5*time.Second)
if err != nil {
t.Skipf("cannot connect to %s: %v", sockPath, err)
}
c.Close()
}
10 changes: 6 additions & 4 deletions metricbeat/module/kvm/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import (

func TestFetchEventContents(t *testing.T) {
conn := libvirttest.New()
defer conn.Close()

f := mbtest.NewReportingMetricSetV2Error(t, getConfig(conn))
host := "test://" + conn.RemoteAddr().String() + ":123"
f := mbtest.NewReportingMetricSetV2Error(t, getConfig(host))

events, errs := mbtest.ReportingFetchV2Error(f)
if len(errs) > 0 {
Expand All @@ -52,18 +54,18 @@ func TestFetchEventContents(t *testing.T) {

t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), e)

statName, err := e.MetricSetFields.GetValue("stat.state")
statName, err := e.MetricSetFields.GetValue("state")
if err == nil {
assert.EqualValues(t, statName.(string), "running")
} else {
t.Errorf("error while getting value from event: %v", err)
}
}

func getConfig(conn *libvirttest.MockLibvirt) map[string]interface{} {
func getConfig(host string) map[string]interface{} {
return map[string]interface{}{
"module": "kvm",
"metricsets": []string{"status"},
"hosts": []string{"test://" + conn.RemoteAddr().String() + ":123"},
"hosts": []string{host},
}
}