Hi Ken,
----- Original Message -----
> [...]
> I'm back looking at this one.
>
> It appears that get_metric_value() is returning a scalar value of 0 when
> values are not available for the metric ... this is sort of a problem when
> the caller wraps this in sum(...) because scalar 0 is not iterable.
>
> I explored fixing this in get_metric_value() but we have no way to decide if
> we should return 0 or [0] there because if the metric is not defined there
> is no pmDesc.
>
> So, I think the caller has to test, and this leads to this ugliness:
>
> try:
> sum_compressed =
> sum(self.ss.get_metric_value('network.interface.in.compressed'))
> except TypeError as te: # pylint: disable-msg=C0103
> sum_compressed = 0
>
> Is this the best one can do? Is the pyrlint chatter needed?
>
> If so, we'll end up with these turdlets throughout the code in every place
> where a function assuming an iterable is used with an argument that comes
> from a get_metric_value() call that might involve a metric that is not
> available.
I don't think its a hugely common pattern there - looks like only reporting for
the network interface metrics (which we don't provide metric totals for, so it
looks like pcp-collectl.py does it itself) ... in which case, it may be easiest
if we just provide a little helper function for that situation.
See attached patch - uses a loop to avoid the TypeError, and keeps it all local
to the network metric reporting. How does that fare with the QA test?
cheers.
--
Nathan
pmcollectl.patch
Description: Text Data
|