In the context of user-defined hooks (e.g. in `before_fork`), the previous naming had the unfortunate side-effect of causing `JSON` to resolve to `Puma::JSON` rather than, the likely more expected, `::JSON` module.
Closes#2639
* Add basic JSON serializer
For now, it only handles Arrays of Integers, but we'll extend it to
support all of the common types
* Serialize Strings
* Escape quotes in Strings
* Escape backslashes in Strings
* Serialize Hashes with String keys
* Extract method for serializing Strings
* Add test coverage for non-Hash non-Array JSON serialization
* Add test for unexpected key types
* Serialize Hashes with Symbol keys
* Raise on unexpected value types
* Serialize boolean values
* Serialize Floats
* Add module comment to Puma::JSON
* Update integration test to use fully-qualfied JSON module reference
* Remove json gem dependency from /stats status server response
Fixes a bug where requesting `/stats` from the status server would cause
subsequent phased restarts to fail when upgrading/downgrading the json
gem.
* Run gc_stats tests on JRuby
These were disabled at some point on JRuby, but they seem to run fine.
Importantly, this test ensures that a call to `/gc-stats` returns
well-formed JSON on JRuby, where the value of `GC.stat` contains nested
structures.
* Remove json gem dependency from /gc-stats status server response
Fixes a bug where requesting `/gc-stats` from the status server would cause
subsequent phased restarts to fail when upgrading/downgrading the json
gem.
* Remove json gem from /thread-backtraces status server response
Fixes a bug where requesting `/thread-backtraces` from the status server
would cause subsequent phased restarts to fail when
upgrading/downgrading the json gem.
* Remove json gem dependency from Puma.stats
Fixes a bug where accessing `Puma.stats` would cause subsequent phased
restarts to fail when upgrading/downgrading the json gem.
* Fix test name in json test
Co-authored-by: rmacklin <1863540+rmacklin@users.noreply.github.com>
* Add History entry
* Add test for exceptions on values of unexpected types
* Update test name for additional clarity
* Reorder cases to match order in ECMA-404
* Allow all serializable inputs in Puma::JSON::serialize
The pervious implementation was based on and older JSON standard which
defined JSON texts to be either objects or arrays. Modern JSON standands
allow all JSON values to be valid JSON texts.
* Update JSON tests to test value types directly
* Reorder tests to roughly match source order
* Add test for serializing integers as JSON
* Serialize nil as null
* Use block form of gsub instead of hash form
* Escape control characters as required by ECMA-404
* Collapse handling of Symbol and String into one case
* Extract constants used in string serialization
* Remove superflous else case
* Use stringio for incremental JSON construction
* Extract test helper for testing JSON serialization
* Assert that strings generated by Puma::JSON roundtrip when using ::JSON
* Use a recent version of the json gem in tests
`::JSON.parse` doesn't handle JSON texts other than objects and arrays
in old versions
* Handle default expected_roundtrip more explicitly for clarity
Co-authored-by: rmacklin <1863540+rmacklin@users.noreply.github.com>
Having access to the hash allows to produce stats in other ways (such as StatsD) without having to parse JSON of data that is available in memory. An example of this workaround is fa6ba1f507/lib/puma/plugin/statsd.rb (L112-L114)
* Add pumactl command to print thread backtraces
Completes 1 of 2 items from #1964
This commit adds an endpoint to the status app to print thread
backtraces, and control cli command to call that endpoint.
I tried this locally by starting a server with:
```sh
bundle exec bin/puma test/rackup/hello.ru \
--control-url="unix://test.sock" \
--control-token="token"
```
and then printing the backtraces with:
```sh
bundle exec bin/pumactl thread-backtraces \
--control-url="unix://test.sock" \
--control-token="token"
```
* Log threads as JSON in control app
With this commit the status app sends the thread backtraces as an array
of objects with `name` and `backtrace` keys, rather than as a string
matching the SIGINFO output.
While working on this I noticed that we logged the thread TID twice.
This commit simplifies that so we only log the thread TID once, with
both the label (I don't know when the label would get set) and name if
they are available.
* Add frozen string literal everywhere it wasnt already
* Enforce stopgap for tests
* Small amount of integration test cleanup
* Parallelize and freeze Test_app_status
* Big cleanup for test_binder
* Whitespace fix
* Fix: Invalid JSON on gc-stats
Credits of this patch should be for @jdsundberg, who reported the issue
but never sent a patch. Link to his bug report is below.
Closes#1687.
* Update tests so JSON response is correctly parsed
JSON without a whitespace between key and values wasn't being correctly
parsed (for example: `key: 'value'` was processed ok, but `key:'value'`
wasn't).