Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding missing until query string from config #60

Closed
wants to merge 1 commit into from

Conversation

inno-ron
Copy link

@inno-ron inno-ron commented Nov 7, 2017

Pull Request Checklist

Is this in reference to an existing issue?

General

  • Update Changelog following the conventions laid out on Keep A Changelog

  • Update README with any necessary configuration snippets

  • Binstubs are created if needed

  • RuboCop passes

  • Existing tests pass

New Plugins

  • Tests

  • Add the plugin to the README

  • Does it have a complete header as outlined here

Purpose

Known Compatablity Issues

@inno-ron
Copy link
Author

inno-ron commented Nov 7, 2017

#58

@majormoses
Copy link
Member

Thanks for your contribution to Sensu plugins! Without people like you submitting PRs we couldn't run the project. I will review it shortly.

@majormoses majormoses self-requested a review November 8, 2017 05:17
Copy link
Member

@majormoses majormoses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding, triaging, and proposing a fix for this issue!

I am not 100% sure that my suggestion is required but it certainly seems safer to me.

We need a changelog entry like this and a testing artifact

@@ -79,7 +79,7 @@ def retrieve_data!
config[:server].prepend('http://')
end

url = "#{config[:server]}/render?format=json&target=#{formatted_target}&from=#{config[:from]}"
url = "#{config[:server]}/render?format=json&target=#{formatted_target}&from=#{config[:from]}&until=#{config[:until]}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I read here it does not appear to be a quired field and I am pretty sure if someone does not specify that it will evaluate to nil or brick. I think we should probably do something like this:

url = if !config[:until].nil?
        "#{config[:server]}/render?format=json&target=#{formatted_target}&from=#{config[:from]}&until=#{config[:until]}"
      else
        "#{config[:server]}/render?format=json&target=#{formatted_target}&from=#{config[:from]}"
      end

That being said I don't know that from is either we might want to create a helper function that loops through the list of defined variables and adds them to the string. Something along these lines:

def build_render_query(config)
  url = "#{config[:server]}/render?format=json&target=#{formatted_target}"
  if !config[:from].nil?
    url += "&from=#{config[:from]}"
  if !config[:until].nil?
    url += "&until=#{config[:until]}"
  end
  url
end

then you can set url = build_render_query(config) where the current url definition is.

@eheydrick thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@majormoses FWIW: if you specify either the from or until parameters without a value, it still works as expected. See https://github.com/graphite-project/graphite-web/blob/2a897cf15a1ad9beb2f919267ef98ce40271bea6/webapp/graphite/metrics/views.py#L75:L83 for the code. Also tested on a live Graphite instance.

Actually a proper fix would be:

  • filter out nil values (although it doesn't appear to be necessary).
  • build the actual query string component using URI.encode_www_form() so everything is properly encoded.

@inno-ron Can I help you with this PR?

@majormoses
Copy link
Member

closing due to lack of response, to get this through you can either re-open the PR or open a new one.

@multani sounds like you are willing to work on making this happen. Ping me if I can be of any assistance.

@majormoses majormoses closed this Sep 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants