Aestek 8709213d6e Prevent status flap when re-registering a check (#4904)
Fixes point `#2` of: https://github.com/hashicorp/consul/issues/4903

When registering a service each healthcheck status is saved and restored (https://github.com/hashicorp/consul/blob/master/agent/agent.go#L1914) to avoid unnecessary flaps in health state.
This change extends this feature to single check registration by moving this protection in `AddCheck()` so that both `PUT /v1/agent/service/register` and `PUT /v1/agent/check/register` behave in the same idempotent way.

#### Steps to reproduce
1. Register a check :
```
curl -X PUT \
  http://127.0.0.1:8500/v1/agent/check/register \
  -H 'Content-Type: application/json' \
  -d '{
  "Name": "my_check",
  "ServiceID": "srv",
  "Interval": "10s",
  "Args": ["true"]
}'
```
2. The check will initialize and change to `passing`
3. Run the same request again
4. The check status will quickly go from `critical` to `passing` (the delay for this transission is determined by https://github.com/hashicorp/consul/blob/master/agent/checks/check.go#L95)
2019-01-07 13:53:03 -05:00
..
2019-01-07 12:48:44 -05:00
2018-11-02 12:00:39 -05:00
2018-10-19 12:04:07 -04:00
2018-03-27 10:59:42 -05:00
2018-10-19 12:04:07 -04:00
2018-10-19 12:04:07 -04:00
2018-10-19 12:04:07 -04:00
2018-10-19 12:04:07 -04:00
2018-10-19 12:04:07 -04:00
2018-10-19 12:04:07 -04:00
2018-11-14 22:37:47 +00:00
2018-10-19 12:04:07 -04:00
2018-10-19 08:41:03 -07:00
2018-02-12 10:15:31 -08:00
2018-02-12 10:15:31 -08:00
2018-09-05 13:38:13 -07:00
2018-02-12 10:15:31 -08:00
2018-02-12 10:15:31 -08:00
2018-02-12 10:15:31 -08:00
2018-10-19 12:04:07 -04:00
2018-03-19 16:56:00 +00:00