Skip to content

Commit

Permalink
fix(cloned-vm): fixing scraping while cloning a vm
Browse files Browse the repository at this point in the history
* Ignore VM if field 'runtime.host' does not exist. This is happen on cloning a VM
  • Loading branch information
pryorda authored Mar 24, 2019
1 parent 40ddbb2 commit a40b30a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ repos:
- --autofix
- id: flake8
stages: [commit]
args:
- --ignore=F705,E123
- repo: https://github.com/pryorda/dockerfilelint-precommit-hooks
rev: v0.1.0
hooks:
Expand Down
39 changes: 37 additions & 2 deletions tests/unit/test_vmware_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def test_collect_vms():

collector.__dict__['vm_labels'] = _succeed({
'vm-1': ['vm-1', 'host-1', 'dc', 'cluster-1'],
'vm-2': ['vm-2', 'host-1', 'dc', 'cluster-1'],
'vm-3': ['vm-3', 'host-1', 'dc', 'cluster-1'],
})

metrics = collector._create_metric_containers()
Expand All @@ -87,11 +89,44 @@ def test_collect_vms():
'guest.toolsStatus': 'toolsOk',
'guest.toolsVersion': '10336',
'guest.toolsVersionStatus2': 'guestToolsUnmanaged',
}
},
'vm-2': {
'name': 'vm-2',
'runtime.powerState': 'poweredOff',
'summary.config.numCpu': 1,
'summary.config.memorySizeMB': 1024,
'runtime.bootTime': boot_time,
'snapshot': snapshot,
'guest.disk': [disk],
'guest.toolsStatus': 'toolsOk',
'guest.toolsVersion': '10336',
'guest.toolsVersionStatus2': 'guestToolsUnmanaged',
},
'vm-3': {
'name': 'vm-3',
'runtime.host': vim.ManagedObject('host-1'),
'runtime.powerState': 'poweredOff',
'summary.config.numCpu': 1,
'summary.config.memorySizeMB': 1024,
'runtime.bootTime': boot_time,
'snapshot': snapshot,
'guest.disk': [disk],
'guest.toolsStatus': 'toolsOk',
'guest.toolsVersion': '10336',
'guest.toolsVersionStatus2': 'guestToolsUnmanaged',
},
})
yield collector._vmware_get_vms(metrics)
assert _check_properties(batch_fetch_properties.call_args[0][1])

# Assert that vm-3 skipped #69/#70
assert metrics['vmware_vm_power_state'].samples[1][1] == {
'vm_name': 'vm-3',
'host_name': 'host-1',
'cluster_name': 'cluster-1',
'dc_name': 'dc',
}

# General VM metrics
assert metrics['vmware_vm_power_state'].samples[0][1] == {
'vm_name': 'vm-1',
Expand Down Expand Up @@ -244,7 +279,7 @@ def test_collect_vm_perf():
'name': 'vm-2',
'obj': vim.ManagedObject('vm-2'),
'runtime.powerState': 'poweredOff',
}
},
})

yield collector._vmware_get_vm_perf_manager_metrics(metrics)
Expand Down
5 changes: 5 additions & 0 deletions vmware_exporter/vmware_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ def _vmware_get_vms(self, metrics):
virtual_machines, vm_labels = yield parallelize(self.vm_inventory, self.vm_labels)

for moid, row in virtual_machines.items():
# Ignore vm if field "runtime.host" does not exist
# It will happen during a VM is cloning
if 'runtime.host' not in row:
continue

labels = vm_labels[moid]

if 'runtime.powerState' in row:
Expand Down

0 comments on commit a40b30a

Please sign in to comment.