-
Notifications
You must be signed in to change notification settings - Fork 9
[bug] The cursor_size logger is misleading #26
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
base: main
Are you sure you want to change the base?
Changes from all commits
62cab6a
2476171
3f67ddf
84d8097
436b3c1
9eb056b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,9 +103,15 @@ public function __construct( | |
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public function encode(Templatable $obj): string | ||
| public function encode($obj): string | ||
| { | ||
| $json = Helpers::json_encode($obj->to_template()); | ||
| if ($obj instanceof Templatable) { | ||
| $json = Helpers::json_encode($obj->to_template()); | ||
| } elseif (is_string($obj)) { | ||
| $json = $obj; | ||
| } else { | ||
| throw new \InvalidArgumentException(sprintf("%s type is not supported", get_class($obj))); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should document this in the method's phpdoc, since now it doesn't match the parent class |
||
| } | ||
| $compressed = gzdeflate($json); | ||
| $encrypted = openssl_encrypt($compressed, self::CIPHER, $this->encrypt_key, 0, $this->initial_vector); | ||
| $signature = $this->compute_signature($encrypted); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -171,27 +171,34 @@ public static function encode( | |||||||||
| $current_user_id | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| $encoded = $binary_codec->encode($cursor); | ||||||||||
| $json = Helpers::json_encode($cursor->to_template()); | ||||||||||
| $encoded = $binary_codec->encode($json); | ||||||||||
| $encoded = Helpers::base64UrlEncode($encoded); | ||||||||||
|
|
||||||||||
| $cursor_size = strlen($encoded); | ||||||||||
| $context = $context ?? 'unknown'; | ||||||||||
| StreamBuilder::getDependencyBag()->getLog() | ||||||||||
| ->histogramTick('cursor_size', $context, ($cursor_size / 1000.0)); | ||||||||||
|
|
||||||||||
| if (($cache_provider instanceof CacheProvider) && ($cursor_size > $cache_size_threshold)) { | ||||||||||
| StreamBuilder::getDependencyBag()->getLog() | ||||||||||
| ->rateTick('cursor_ops', 'cached'); | ||||||||||
| $cache_codec = new CacheCodec( | ||||||||||
| $cache_provider, | ||||||||||
| CacheProvider::OBJECT_TYPE_CURSOR, | ||||||||||
| CacheCodec::SERIALIZATION_TYPE_JSON | ||||||||||
| CacheCodec::SERIALIZATION_TYPE_JSON_STRING | ||||||||||
| ); | ||||||||||
| $encoded = $cache_codec->encode($cursor); | ||||||||||
| $encoded = $cache_codec->encode($json); | ||||||||||
| // base64 url encode cache encoded as well, to line up with binary codec encoded logic. | ||||||||||
| $encoded = Helpers::base64UrlEncode($encoded); | ||||||||||
|
|
||||||||||
| // This is an implementation detail, but the CacheCodec does not base64 encode the payload before | ||||||||||
| // writing to cache, so the original cursor_size is misleading. Base64 encoding can increase the | ||||||||||
| // payload size by 33%. | ||||||||||
| $cursor_size = strlen($json); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| StreamBuilder::getDependencyBag()->getLog() | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is it going to be a bad idea to add another tick to track just the thing that goes into a URL, and leave the existing tick to track what gets cached? |
||||||||||
| ->histogramTick('cursor_size', $context, ($cursor_size / 1000.0)); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't we losing visibility in what is going to be cached with this change?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we'd actually get a clearer picture of what size ended up being persisted somewhere, as the comment above points out
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be worth adding an actual INFO or DEBUG level log here too, so we can get some hard data rather than just time series info |
||||||||||
|
|
||||||||||
| return $encoded; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn, need union types 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two functions and adjust call site(s)