Skip to content

Encode telemetry ping query values - #36

Open
theluckystrike wants to merge 1 commit into
cronitorio:masterfrom
theluckystrike:encode-ping-params
Open

theluckystrike wants to merge 1 commit into
cronitorio:masterfrom
theluckystrike:encode-ping-params

Conversation

@theluckystrike

Copy link
Copy Markdown

Monitor#ping passes a custom query_string_normalizer to HTTParty so metrics go out as metric=foo:1 instead of metric[]=foo:1. The normalizer joins "#{k}=#{v}" without encoding, so any value with a reserved character is mangled:

  • & ends the value: message=undefined method 'x' for nil & co #42 reaches the API as message=undefined method 'x' for nil plus a bogus co #42 parameter
  • + turns into a space and = inside a value is ambiguous
  • the same applies to host, env, series and metric values

Cronitor.job sends e.message on failure, so exception text that contains these characters showed up cut short in Cronitor.

This change form-encodes every value and every metric inside the normalizer (URI.encode_www_form_component) and keeps the metric= repeat format. Plain values such as run, complete or a float stamp are sent the same as before.

The new spec captures the normalizer from the HTTParty.get call, builds the query string and decodes it again. It fails on master (the message comes back as undefined method 'x' for nil ) and passes with the change. The full spec suite passes locally (35 examples, 0 failures).

The custom query_string_normalizer joined keys and values without
encoding them. A fail message such as an exception text with & or #
was cut at that character, the rest became a bogus parameter, and a +
turned into a space. Cronitor.job sends e.message on failure, so the
message shown in Cronitor could lose most of the error.

Form-encode every value and every metric in the normalizer and add a
spec that decodes the built query string and compares the message,
host and metric.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant