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

Fix base64 encoding issue in stats #7187

Merged
merged 1 commit into from
Aug 23, 2016
Merged

Fix base64 encoding issue in stats #7187

merged 1 commit into from
Aug 23, 2016

Conversation

e-dard
Copy link
Contributor

@e-dard e-dard commented Aug 22, 2016

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated

Fixes #7177.

This PR changes the tags in /debug/vars to use a map[string]string, which ensures they're encoded correctly in the JSON response, as well as saving on some cycles by reducing the amount of sorting and hashing we are doing of various values.

It also fixes some possible bugs:

  • opentsdb.Service.Statistics was ignoring any passed in tags;
  • udp.Service.Statistics was ignoring any passed in tags;
  • subsriber.balancewriter.Statistics was overwriting passed in tags with default values.

@jwilder @sparrc @corylanou

@mention-bot
Copy link

@e-dard, thanks for your PR! By analyzing the annotation information on this pull request, we identified @joelegasse and @gunnaraasen to be potential reviewers

@benbjohnson
Copy link
Contributor

👍

1 similar comment
@jwilder
Copy link
Contributor

jwilder commented Aug 22, 2016

👍

@jwilder jwilder added this to the 1.1.0 milestone Aug 22, 2016
@sparrc
Copy link
Contributor

sparrc commented Aug 22, 2016

excellent, thanks!

@sparrc
Copy link
Contributor

sparrc commented Aug 22, 2016

can this be cherry-picked into 1.0?

@jwilder
Copy link
Contributor

jwilder commented Aug 22, 2016

@sparrc @e-dard Checked an this does not exist on 1.0. It's only in the current nightlies.

@jsternberg
Copy link
Contributor

jsternberg commented Aug 23, 2016

I think a better way to do this would be just to make a MarshalJSON method on the models.Tags object and change nothing else. If you do something like this, this change is trivial.

func (s *Statistic) MarshalJSON() ([]byte, error) {
    var o struct {
        Name string `json:"name"`
        Tags map[string]string `json:"tags"`
        Values map[string]interface{} `json:"values"`
    }

    o.Name = s.Name
    o.Tags = s.Tags.Map()
    o.Values = s.Values
    return json.Marshal(&o)
}

Then you don't have to make any other changes and you potentially get the performance improvements you're supposed to get from Ben's change to reduce memory allocations.

@e-dard e-dard merged commit a2fcafd into master Aug 23, 2016
@e-dard
Copy link
Contributor Author

e-dard commented Aug 23, 2016

@jsternberg that was the initial quick-fix yes. But then looking through the code it was clear there was a lot of extra complexity we could remove.

I don't think we would get any performance improvements with the Tags approach because we always start with a map[string]string in Statistics calls which we then have to convert into models.Tags.

@mark-rushakoff mark-rushakoff deleted the er-stat-fix branch August 24, 2016 23:05
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.

/debug/vars endpoint returns base64 encoded strings
6 participants