What is "Expect Negative Result" used for?
Short answer
Expect Negative Result inverts the result of every check: when the check fails, the server is considered healthy, and when it succeeds, the server is considered unhealthy; it is off by default. Its typical use is to remove the server from traffic when a maintenance flag (e.g. a /maintenance.flag file) exists on the server. Since a timeout, a connection refusal and a wrong address are also counted as failures, configuration errors can make the server appear healthy while this option is on; the option is turned on only when this behavior is wanted.
How Does It Work?
- The check is performed normally (e.g. an HTTP request, the expected status code and the content check).
- The result of every check is inverted before the threshold counting: every kind of error (timeout, connection refusal, certificate error, unexpected status code, content mismatch) is counted as a success, and a successful check is counted as an error.
- The Required Successes and Required Failures thresholds are counted over the inverted result.
Example: Maintenance Flag
| Field | Value |
|---|---|
| Check Type | HTTP |
| Path + Query | /maintenance.flag |
| Expected Status Codes | 200: OK |
| Expect Negative Result | On |
While /maintenance.flag does not exist on the server, the request returns 404; the check fails, and since it is inverted, the server is considered healthy. When the application team creates the file, the request returns 200, and the server is considered unhealthy after Required Failures consecutive checks and is removed from traffic. When the file is deleted, the server returns to traffic after Required Successes consecutive checks.
In TR7
- Location: Load Balancer → Profiles → Health Checks → profile → Expect Negative Result (off by default). It is present in all types except Scenario, including Expression (JSONata).
- Scenario: It is not on the main form of the scenario; it can be turned on separately in the window of each sub-check in the scenario (The fields of the checks within the scenario).
- WEB-CLI:
--negate true(The threshold fields found in every type). - View: In the Details tab of the profile preview, Enabled is written in the Expect Negative Result row (Preview of the selected profile); the summary of every record in the Health Checks tab starts with "Expect negative result".
Common Misconceptions
- "It inverts only the status code." The entire result of the check is inverted, including network errors.
- "If I enter a wrong address or port, the server goes down." While this option is on, a failure to establish a connection is counted as a success and the server appears healthy.
- "This is the only way to put a server into maintenance." The Maintenance Mode setting of the Backend Service is the path managed by TR7; this option is used to manage maintenance from the server side.
How it is done in the documentation
