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

stats: add new TextReadout stat type #5844

Closed
wants to merge 3 commits into from

Conversation

fredlas
Copy link
Contributor

@fredlas fredlas commented Feb 5, 2019

Description: Add the TextReadout stat type, for holding (max 15 bytes) strings. A followup PR will migrate the 64-bit hash gauges.

I chose TextReadout because Text/TextSharedPtr is not obviously something other than a slightly-wrapped string; in particular it's not obvious that it's a stat. On the other hand, I wasn't entirely sure if just Readout would imply a string strongly enough to make everyone happy. I'm open to suggestions (including chopping it down to Readout).

We could get to 16 bytes if we're willing to use bits in the Metric's flags to store length, but the need to stay within the numeric stats' memory footprint is temporary anyways.

Risk Level: low
Testing: roughly duplicated every bit of test logic involving the word "gauge", added thorough test of the split-across-two-uint64_ts string storage

#4974 #5770 #5790 @ramaraochavali

Signed-off-by: Fred Douglas <fredlas@google.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
@htuch htuch requested a review from jmarantz February 5, 2019 19:56
@mattklein123 mattklein123 self-assigned this Feb 5, 2019
/**
* A string, possibly non-ASCII.
*/
class TextReadout : public virtual Metric {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about TextGauge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, this new class is meant to remove the need to abuse gauges, so in some sense it's explicitly not a gauge. The name "gauge" suggests the image of a circle with numbers and a needle bouncing around, like what comes up in a Google image search for "gauge".

Copy link
Contributor

Choose a reason for hiding this comment

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

:-) . Agree. It sounds more like a numeric thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this to indicate that it s a stat? If yes, may be

TextMetric/TextStat/TextValuedStat may convey it more obviously?

Another thing, I was looking statsd and prometheus documentation and they do not seem to support text type of stats - so if we migrate the 64-bit hash gauges to this do we have to worry about the existing users?

htuch pushed a commit that referenced this pull request Feb 7, 2019
This PR adds API support required for #5770 . Once #5844 lands, I will output it using the text stat.

Risk Level: Low
Testing: N/A

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>
uint64_t data2 = 0;
uint8_t* data1_ptr = reinterpret_cast<uint8_t*>(&data1);
uint8_t* data2_ptr = reinterpret_cast<uint8_t*>(&data2);
uint8_t total_length = static_cast<uint8_t>(value.length() <= 15 ? value.length() : 15);
Copy link
Contributor

Choose a reason for hiding this comment

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

std::min(15, value.length);

uint8_t* data1_ptr = reinterpret_cast<uint8_t*>(&data1);
uint8_t* data2_ptr = reinterpret_cast<uint8_t*>(&data2);
uint8_t total_length = static_cast<uint8_t>(value.length() <= 15 ? value.length() : 15);
int length1 = total_length <= 7 ? total_length : 7;
Copy link
Contributor

Choose a reason for hiding this comment

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

std::min(7, total_length);

@@ -167,6 +169,73 @@ class NullGaugeImpl : public Gauge {
uint64_t value() const override { return 0; }
};

/**
* TextReadout implementation that wraps a StatData. Max length 15; set() will truncate.
Copy link
Contributor

Choose a reason for hiding this comment

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

per f2f conversation this is really cool but if we wait till your hot-restart-without-shm PR then this can be simpler and not have limits.

Does it make sense to wait till then?

Copy link
Contributor

Choose a reason for hiding this comment

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

also during an update an observer might see garbage for the string the atomic behavior is per-uint64. In fact the length might be adjusted and expose old data, which is technically a security hole, though you only get 15 bytes of data through :)

@stale
Copy link

stale bot commented Feb 15, 2019

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Feb 15, 2019
@jmarantz
Copy link
Contributor

Per discussion I think we should temporarily close this one, and re-open after shm stats are no longer needed for hot-restart. @fredlas is that OK?

@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Feb 15, 2019
@fredlas
Copy link
Contributor Author

fredlas commented Feb 15, 2019

Sure, makes sense.

@fredlas fredlas closed this Feb 15, 2019
fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
This PR adds API support required for envoyproxy#5770 . Once envoyproxy#5844 lands, I will output it using the text stat.

Risk Level: Low
Testing: N/A

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
@fredlas fredlas deleted the TXT_text_readout branch October 9, 2019 18:06
@efimki
Copy link
Contributor

efimki commented Apr 2, 2020

Can we reopen this?
Per conversation with @fredlas we should be able to add arbitrary strings now.

@jmarantz
Copy link
Contributor

jmarantz commented Apr 2, 2020

I don't think we can re-open the PR as it's on a deleted branch, but I re-opened #5790 to track the request.

Feel free to try to patch this PR into a new branch and go for it, but be aware that some of the underlying code this PR changes might have changed to much to make this patchable.

efimki added a commit to efimki/envoy that referenced this pull request Apr 6, 2020
Based on envoyproxy#5844 by @fredlas.

Signed-off-by: Misha Efimov <mef@google.com>
jmarantz pushed a commit that referenced this pull request Apr 17, 2020
* stats: add new TextReadout stat type
Based on #5844 by @fredlas.

Signed-off-by: Misha Efimov <mef@google.com>
penguingao pushed a commit to penguingao/envoy that referenced this pull request Apr 22, 2020
* stats: add new TextReadout stat type
Based on envoyproxy#5844 by @fredlas.

Signed-off-by: Misha Efimov <mef@google.com>
Signed-off-by: pengg <pengg@google.com>
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.

5 participants