Ensure that label values are strings in APCNg adapter #159
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
APCNg is crashing if the label value provided wasn't a string, but something that can be coerced to string (such as int). Other adaptors work properly in this situation.
The problem occurs in two different places:
storeLabelKeys()
calls intoaddItemToKey()
which has its second parameter type hinted as astring
and throws a type error if anything else is passed. This results in partially stored state;APCng::collect()
will try to build all the permutations and expect all the key-value pairs for labels to exist, but numeric label values aren't persisted and so it will cause theUndefined array key
error as reported in APCng crashing when rendering with integer labels #154;This change ensures that label values are cast to the
string
type before encoding them and using as APC keys.An alternative that can be considered is adding a label check / cast at the individual collector layers. Given other adaptors work properly – this solution seemed fitting. Introducing a check into the collectors layer will cause a breaking change, so probably isn't the best option.
Fixes #154