1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
Commit graph

25 commits

Author SHA1 Message Date
Robin Wallin
0256d71e60
Rename Puma::JSON to Puma::JSONSerialization (#2640)
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
2021-06-09 08:55:45 -06:00
Chris LaRose
64c0153cd0
Remove use of json gem (#2479)
* 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>
2020-11-10 10:16:42 -07:00
MSP-Greg
992a4076c1
Refactor status.rb - dry it up a bit (#2450)
Replace multiple regexes with single, consolidate responses, add some comments
2020-10-25 14:49:38 -06:00
MSP-Greg
fe31aadd5b Load JSON at runtime
Closes #2206
2020-05-17 11:59:39 -05:00
Will Jordan
613ac8e803 Add fork_worker option and refork command
Trigger refork for improved copy-on-write performance.
2020-05-01 17:21:32 -07:00
Bart
1bec245b63 Change Puma.stats to return a hash instead of a JSON string (#2086)
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)
2019-12-17 12:38:48 +07:00
Daniel Colson
39d16fadaf Add pumactl command to print thread backtraces (#2054)
* 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.
2019-11-11 13:08:41 +08:00
Nate Berkopec
b18250f1b5
Status app: privatize auth, no more explicit returns 2019-09-20 12:45:56 +02:00
Jesús Burgos Maciá
6dd084bd3b Merge files documenting configuration options (#1883) 2019-08-05 17:30:43 -07:00
Nate Berkopec
4c85facff3
Test cleanup and parallelization (#1846)
* 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
2019-07-16 18:53:28 -04:00
Jesús Burgos Maciá
2db1ef10f7 Fix: Invalid JSON on gc-stats (#1801)
* 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).
2019-05-21 07:43:18 -05:00
Noah Gibbs
0d7a8bb5f3 Add /gc URL to status server to do a major GC. Add a /gc-status URL to get GC.stats as JSON. (#1384) 2017-08-03 15:46:49 -06:00
Evan Phoenix
f788af0c8f Continue API cleanup, preparing for 3.0 2016-02-06 19:00:29 -08:00
Rubén Caro
48b50a312f Add reload_worker_directory 2014-02-25 14:52:20 +01:00
Michael J. Cohen
678a6c73c9 Fix typo in phased-restart response
Sponsored-by: CentroNet Marketing
2013-08-06 15:47:40 -04:00
Evan Phoenix
c48b804d8f Refactor modes, fix control server to always work 2013-07-05 16:08:13 -07:00
Paco Viromontes
a2a53316c3 allow for alternate locations for status app 2012-10-03 18:16:31 -07:00
Evan Phoenix
27b2f8e60a Formatting fix 2012-07-19 16:38:16 -07:00
Konstantin Haase
3dc2a76211 use #bytesize instead of #length for Content-Length header 2012-05-13 02:27:14 +03:00
jc00ke
29a71026f1 Use correct Content-Type 2012-04-29 12:24:00 -07:00
jc00ke
ede98dadfd Return valid Rack responses from status server
Use Rack::Lint to check the response is valid. Existing code really just
needed Content-Length & Content-Type headers.
2012-04-29 12:18:21 -07:00
Evan Phoenix
892084657f + Add ability to inherit server sockets on restart 2012-04-04 11:38:22 -04:00
Evan Phoenix
a91d64a560 Add auth token support to App::Status 2011-12-06 16:22:02 -08:00
Evan Phoenix
d8026e87f4 Add ability to restart by reexecing and pumactl to use it
This allows all existing requests to finish, but does not keep the same
socket alive across the exec, so this is not a graceful as it could be.
2011-12-05 15:58:23 -08:00
Evan Phoenix
c5aad50eb4 Add App::Status rack app to control a server
Puma::App::Status is a rack app that can be used to control the current
server. It allows a server to be queried remotely programmaticly.
2011-12-05 09:01:19 -08:00