Commit graph

14 commits

Author SHA1 Message Date
Giuseppe Lavagetto
2a77862c52 Expose the latest modified index seen by EtcdConfig
While not immediately useful for fecthing the configuration, this is
basically a version information about the configuration currently loaded
from etcd. A typical use-case for this index is monitoring the freshness
of the configuration across a cluster of servers.

Bug: T182597
Change-Id: I58189d36a5b620fb44323bae87257f085a64386e
2018-03-01 13:44:15 +01:00
Kunal Mehta
79de8fd02f Use wikimedia/object-factory 1.0.0
Deprecate the unnamespaced version and move it to includes/compat.

Bug: T147167
Depends-On: I39c805bfb98b32f32f3d0dc1eee9e823afe1c21a
Change-Id: I3780c7adf51683f3f7adb35a88f9a25a0a2e2530
2018-02-04 12:52:44 -08:00
Tim Starling
95bf0043ef EtcdConfig: allow slashes in config key names
Allowing slashes in config key names allows us to trivially support the
proposed hierarchical structure with a single EtcdConfig object, by
fetching values with the relevant prefixes on startup.

Bug: T156924
Change-Id: Ica0914e61baba9c0462481925be15d79b66dc342
2017-09-01 13:42:28 +10:00
Umherirrender
3f1a52805e Use short type bool/int in param documentation
Enable the phpcs sniffs for this and used phpcbf

Change-Id: Iaa36687154ddd2bf663b9dd519f5c99409d37925
2017-08-20 13:20:59 +02:00
Timo Tijhof
63a6926dfd config: Fix invalid EtcdConfig return value after JSON parse error
Follows-up 1f2daa9132, 9b459d29e0, 110a21ea18.

Bug: T156924
Change-Id: I79b7e11b32e5be46c8ebdfb5c937e38e46301c0e
2017-07-24 12:50:26 -07:00
Aaron Schulz
82e2c924e4 Remove "@author Aaron Schulz" annotations
Bug: T139301
Change-Id: Ib5248e8e27d60611c7373bce4b29dd5e85aa3489
2017-06-27 15:24:14 -07:00
Tim Starling
cde44feba3 Improve HTTP logging
* Log HTTP debug lines to the "http" channel instead of wfDebug()
* Add the ability to do debug logging to MultiHttpClient
* Add a static method Http::createMultiClient() which provides a
  MultiHttpClient configured similarly to the way individual requests
  are configured, respecting the wiki's $wgHTTPTimeout and writing debug
  logs.
* In EtcdConfig, pass the logger instance through to the MultiHttpClient
  backend.

Change-Id: Ic5bdcb0cae95d7b3715ab5261758be082751c3ff
2017-05-19 06:49:26 +02:00
Tim Starling
3defb5a11a EtcdConfig: Fix infinite timeout bug, and reduce timeout
removeServer() returns the modified array, rather than passing by
reference, so you have to use the return value to avoid an infinite loop
when a server is down.

Tune the timeout downwards, to 2s. With three servers in the SRV pool,
if they are all unreachable, this will mean an overall request time of
6s, which is conveniently less than the APC lock time and the cache
TTL (9-10s). If the APC lock time is significantly shorter than the time
it takes to do the HTTP requests, then additional threads join in
waiting for the server. This could have stability consequences if the
maximum HHVM worker count is exceeded.

Change-Id: I3176aa41b8833c0ba0b668859e59911cd4392250
2017-05-04 15:07:11 +10:00
Timo Tijhof
c09c8b4e93 config: Use less generic cache key, and not fragmented by wiki
* Use makeGlobalKey instead of makeKey to avoid fragmenting
  the cache by the wiki-specific key space.

* Add "EtcdConfig" and $this->host to the cache key to make
  it less generic and less likely to conflict with unrelated values
  in case multiple instances exist somewhere in the MediaWiki run
  time (or during testing/debugging).

Adding $this->host should be fine given we were already including
the directory within that host. Although I do recognise that we
may want to encourage slow cache rollover instead of instance
cache rollover in case the host name needs to changed. Perhaps
we should have some kind of canonical name for the instance for
the purpose of caching so that directory or host can be changed
without changing the cache key, and thus have cache roll over
normally over the course of 10 seconds, instead of immediately.

On the other hand, deployment will likely already spread things
out a little bit.

In addition, due to the cache being kept indefinitely this means
the old key will stay indefinitely. Perhaps not an issue given
it's just one key, which will clear on restart eventually?

Bug: T156924
Change-Id: I622e6618f2d4171626e4b272bcb11a97a85cb770
2017-05-01 15:06:20 -07:00
Timo Tijhof
110a21ea18 config: Add unit tests for EtcdConfig
Change-Id: I6e647985b98724b5448831a6fae1b2d2521fd363
2017-05-01 21:50:38 +00:00
Aaron Schulz
7fccf0ef9c Improve EtcdConfig fallback logic
If the cache is stale and the lock keeps being acquired, but the re-fetch
fails each time, the method would end up failing after the timeout was
reached. Instead, use the stale cache if available.

Change-Id: Ieafc9de17e6c60d8eea7b937923b4ad548e99be8
2017-04-29 02:43:39 +00:00
Tim Starling
4e62702238 EtcdConfig: use array_key_exists(), the value can be null
Change-Id: Iae175401da8d49f5475d8c88cc5390b16e7cba32
2017-04-28 15:16:26 +10:00
Aaron Schulz
52902b6667 Document which EtcdConfig parameters are optional
Change-Id: Ic6b56ed2f8789ae7920cdfc12f34b00db4a76c3a
2017-04-19 16:48:13 -07:00
Aaron Schulz
9b459d29e0 Add EtcdConfig class
Bug: T156924
Change-Id: I60914d31c21484bfb935fe3d8c3168b51a2d5d1b
2017-04-10 07:36:33 +00:00