Skip to content

Commit c859c49

Browse files
Merge pull request #4 from NHSDigital/dp-APM-2884
Add splunk HEC healthcheck flow
2 parents 8a71080 + 8797445 commit c859c49

4 files changed

Lines changed: 39 additions & 11 deletions

File tree

azure/azure-release-pipeline.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ extends:
3434
- environment: internal-dev
3535
post_deploy:
3636
- template: ./templates/run-smoke-tests.yml
37+
- environment: prod
38+
post_deploy:
39+
- template: ./templates/run-smoke-tests.yml
40+
depends_on:
41+
- internal-dev
3742
# - environment: internal-qa
3843
# post_deploy:
3944
# - template: ./templates/run-smoke-tests.yml
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignMessage.HandleSplunkHec">
3+
<DisplayName>AssignMessage.HandleSplunkHec</DisplayName>
4+
<Properties/>
5+
<Set>
6+
<Payload contentType="application/json" variablePrefix="%" variableSuffix="#">
7+
{
8+
"status_code": %splunkCalloutResponse.status.code#,
9+
"content": %splunkCalloutResponse.content#
10+
}
11+
</Payload>
12+
<StatusCode>200</StatusCode>
13+
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
14+
<AssignTo createNew="false" transport="https" type="request"/>
15+
</Set>
16+
</AssignMessage>

proxies/live/apiproxy/proxies/default.xml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
</Response>
2020
<Condition>(proxy.pathsuffix MatchesPath "/_ping") and ((request.verb = "GET") or (request.verb = "HEAD"))</Condition>
2121
</Flow>
22-
<Flow name="StatusEndpoint">
22+
<Flow name="SplunkStatusMonitor">
2323
<Request>
2424
<Step>
2525
<Condition>request.header.apikey = null or private.common.status-endpoint-api-key != request.header.apikey</Condition>
2626
<Name>RaiseFault.401Unauthorized</Name>
2727
</Step>
2828
<Step>
29-
<Name>ServiceCallout.CallHealthcheckEndpoint</Name>
29+
<Name>FlowCallout.LogToSplunk</Name>
3030
</Step>
3131
</Request>
3232
<Response>
3333
<Step>
34-
<Name>javascript.SetStatusResponse</Name>
34+
<Name>AssignMessage.HandleSplunkHec</Name>
3535
</Step>
3636
</Response>
37-
<Condition>(proxy.pathsuffix MatchesPath "/_status") and ((request.verb = "GET") or (request.verb = "HEAD"))
37+
<Condition>((proxy.pathsuffix MatchesPath "/status") and (request.verb = "GET")) or ((proxy.pathsuffix MatchesPath "/_status") and ((request.verb = "GET") or (request.verb = "HEAD")))
3838
</Condition>
3939
</Flow>
4040
</Flows>
@@ -59,9 +59,15 @@
5959
<RouteRule name="NoRouteStatus">
6060
<Condition>(proxy.pathsuffix MatchesPath "/_status") and ((request.verb = "GET") or (request.verb = "HEAD"))</Condition>
6161
</RouteRule>
62-
<RouteRule name="splunk-monitor-target">
63-
<TargetEndpoint>splunk-monitor-target</TargetEndpoint>
64-
</RouteRule>
62+
<FaultRules>
63+
<FaultRule name="SplunkError">
64+
<Step>
65+
<Name>AssignMessage.HandleSplunkHec</Name>
66+
</Step>
67+
<Condition>(((proxy.pathsuffix MatchesPath "/status") and (request.verb = "GET")) or ((proxy.pathsuffix MatchesPath "/_status") and ((request.verb = "GET") or (request.verb = "HEAD")))) and (splunkCalloutResponse isNot null)
68+
</Condition>
69+
</FaultRule>
70+
</FaultRules>
6571
<DefaultFaultRule>
6672
<Step>
6773
<Name>AssignMessage.Errors.CatchAllMessage</Name>

tests/api_tests.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ async def is_401(resp: ClientResponse) -> bool:
2020
return resp.status == 401
2121

2222

23+
async def is_200(resp: ClientResponse) -> bool:
24+
return resp.status == 200
25+
26+
2327
@pytest.mark.e2e
2428
@pytest.mark.smoketest
2529
def test_output_test_config(api_test_config: APITestSessionConfig):
@@ -65,11 +69,8 @@ async def test_wait_for_status(api_client: APISessionClient, api_test_config: AP
6569
test for _status .. this uses poll_until to wait until the correct SOURCE_COMMIT_ID ( from env var )
6670
is available
6771
"""
68-
69-
is_deployed = partial(_is_deployed, api_test_config=api_test_config)
70-
7172
await poll_until(
7273
make_request=lambda: api_client.get('_status', headers={'apikey': env.status_endpoint_api_key()}),
73-
until=is_deployed,
74+
until=is_200,
7475
timeout=120
7576
)

0 commit comments

Comments
 (0)