blue-yonder / azure-cost-mon

Prometheus exporter for the Azure billing API
MIT License
61 stars 13 forks source link

cast subscription_id to str #17

Closed ghost closed 6 years ago

ghost commented 6 years ago

If subscription_id in the configuration item SUBSCRIPTION_IDS uses unicode a string representation e.g. SUBSCRIPTION_IDS = [u'ecfb1234-1234-123b-abc0-1234cb90d12f']

the following error message is displayed:

Scrape failed: Parameter 'subscription_id' must be str.

Debugging the issue, the following traceback is raised:

Traceback (most recent call last): File "/Users/jweismueller/Coding/venvs/azure-cost-mon/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/Users/jweismueller/Coding/venvs/azure-cost-mon/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/jweismueller/Coding/venvs/azure-cost-mon/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/jweismueller/Coding/venvs/azure-cost-mon/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/Users/jweismueller/Coding/venvs/azure-cost-mon/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request return self.view_functionsrule.endpoint File "/Users/jweismueller/Coding/azure-cost-mon/azure_costs_exporter/views.py", line 70, in metrics content = generate_latest(registry) File "/Users/jweismueller/Coding/venvs/azure-cost-mon/lib/python2.7/site-packages/prometheus_client/exposition.py", line 63, in generate_latest for metric in registry.collect(): File "/Users/jweismueller/Coding/venvs/azure-cost-mon/lib/python2.7/site-packages/prometheus_client/core.py", line 97, in collect for metric in collector.collect(): File "/Users/jweismueller/Coding/azure-cost-mon/azure_costs_exporter/allocated_vm_collector.py", line 85, in collect self._collect_allocated_vms(allocated_vms) File "/Users/jweismueller/Coding/azure-cost-mon/azure_costs_exporter/allocated_vm_collector.py", line 55, in _collect_allocated_vms compute_client = ComputeManagementClient(self._credentials, subscription_id) File "/Users/jweismueller/Coding/venvs/azure-cost-mon/lib/python2.7/site-packages/azure/mgmt/compute/compute_management_client.py", line 75, in init self.config = ComputeManagementClientConfiguration(credentials, subscription_id, base_url) File "/Users/jweismueller/Coding/venvs/azure-cost-mon/lib/python2.7/site-packages/azure/mgmt/compute/compute_management_client.py", line 41, in init raise TypeError("Parameter 'subscription_id' must be str.") TypeError: Parameter 'subscription_id' must be str

Maybe we should additionaly file a bug report in the azure.mgmt.compute package.

Casting the subscription_id fixes the issue right now.

MathMagique commented 6 years ago

Filing an issue with Azure would be a good idea, but the issue seems already fixed: https://github.com/Azure/azure-sdk-for-python/blob/master/azure-mgmt-compute/azure/mgmt/compute/compute_management_client.py#L41

Change done in https://github.com/Azure/azure-sdk-for-python/commit/0489ff9345f8d8f74cd15ec6406a66de6885aff4#diff-433a44198c60035145a426bc490b2538

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling e06c2b3830f66accc3dcecd60c09833f1dbdfd33 on bugfix/cast-subscription-id-to-string into 25aca34b6fecd5ed9629a0d615671e08f11fc24a on master.

MathMagique commented 6 years ago

Ok, apparently the change is in the Azure SDK code base, but not released yet for some reason. Your workaround makes sense, in this case.

ghost commented 6 years ago

Latest release is from 3.0.1 (2017-09-26) , so bugfix is not yet included.

StephanErb commented 6 years ago

This is also worth a changelog entry.

ghost commented 6 years ago

There is a pre-release which already contains the bugfix, see 0489ff9#commitcomment-29754231