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

Check for empty tag value before metric allocation #2404

Closed
wants to merge 4 commits into from
Closed

Check for empty tag value before metric allocation #2404

wants to merge 4 commits into from

Conversation

lpic10
Copy link
Contributor

@lpic10 lpic10 commented Feb 14, 2017

Replaces PR #2396, also fixes #2390

  • CHANGELOG.md updated (we recommend not updating this until the PR has been approved by a maintainer)
  • Sign CLA (if not already signed)
  • README.md updated (if adding a new plugin)

@sparrc
Copy link
Contributor

sparrc commented Feb 14, 2017

@lpic10 few things I would prefer in this PR:

  1. write a unit test for this case in metric_test.go
  2. you don't need to check the length after escaping the tag key/values, just check the raw k,v in the for-loop.
  3. I checked the code and AFAICT we don't currently mutate any of the arguments passed into the metric.New function. With that in mind, I'd prefer that we didn't mutate the tags map, which just means that we'll have to check the length of k & v twice, something like this:
	// pre-allocate exact size of the tags slice
	taglen := 0
	for k, v := range tags {
		if len(k) == 0 || len(v) == 0 {
			continue
		}
		taglen += 2 + len(escape(k, "tagkey")) + len(escape(v, "tagval"))
	}
	m.tags = make([]byte, taglen)

	i := 0
	for k, v := range tags {
		if len(k) == 0 || len(v) == 0 {
			continue
		}
		m.tags[i] = ','
		i++
		i += copy(m.tags[i:], escape(k, "tagkey"))
		m.tags[i] = '='
		i++
		i += copy(m.tags[i:], escape(v, "tagval"))
	}

@lpic10
Copy link
Contributor Author

lpic10 commented Feb 15, 2017

@sparrc applied your suggestions, looks good as it is

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.

Empty tag value causes error on InfluxDB output
2 participants