-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[marathon] Count running/pending deployments (#2788)
* Count running or pending deployments * Helper for loading JSON fixtures. * Tests for marathon checks * Normalize tabs/spaces and tidy whitespace. * Clean up some linty stuff. * Users should explicitly enable deployment-related metrics. * Update example docs for Marathon.
- Loading branch information
Showing
6 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"apps": [ | ||
{ | ||
"id": "/my-app", | ||
"cmd": "/usr/bin/run-app", | ||
"args": null, | ||
"user": null, | ||
"env": { | ||
"ENVIRONMENT": "development" | ||
}, | ||
"instances": 10, | ||
"cpus": 1.0, | ||
"mem": 512, | ||
"disk": 0, | ||
"executor": "", | ||
"constraints": [], | ||
"ports": [ | ||
10002 | ||
], | ||
"portDefinitions": [ | ||
{ | ||
"port": 10002, | ||
"protocol": "tcp", | ||
"labels": {} | ||
} | ||
], | ||
"requirePorts": false, | ||
"backoffSeconds": 1, | ||
"backoffFactor": 1.15, | ||
"maxLaunchDelaySeconds": 3600, | ||
"container": { | ||
"type": "DOCKER", | ||
"volumes": [], | ||
"docker": { | ||
"image": "my-org/my-image:latest", | ||
"network": "BRIDGE", | ||
"portMappings": [ | ||
{ | ||
"containerPort": 80, | ||
"hostPort": 0, | ||
"servicePort": 10002, | ||
"protocol": "tcp", | ||
"labels": {} | ||
} | ||
], | ||
"privileged": false, | ||
"parameters": [], | ||
"forcePullImage": true | ||
} | ||
}, | ||
"healthChecks": [ | ||
{ | ||
"path": "/health", | ||
"protocol": "HTTP", | ||
"portIndex": 0, | ||
"gracePeriodSeconds": 5, | ||
"intervalSeconds": 10, | ||
"timeoutSeconds": 20, | ||
"maxConsecutiveFailures": 3, | ||
"ignoreHttp1xx": false | ||
} | ||
], | ||
"readinessChecks": [], | ||
"dependencies": [], | ||
"upgradeStrategy": { | ||
"minimumHealthCapacity": 0.5, | ||
"maximumOverCapacity": 0.5 | ||
}, | ||
"labels": { | ||
"HAPROXY_0_VHOST": "my-app.my-org.net", | ||
"HAPROXY_GROUP": "my-app" | ||
}, | ||
"acceptedResourceRoles": null, | ||
"ipAddress": null, | ||
"version": "2016-08-25T18:13:34.079Z", | ||
"residency": null, | ||
"versionInfo": { | ||
"lastScalingAt": "2016-08-25T18:13:34.079Z", | ||
"lastConfigChangeAt": "2016-08-25T16:58:48.416Z" | ||
}, | ||
"tasksStaged": 5, | ||
"tasksRunning": 10, | ||
"tasksHealthy": 5, | ||
"tasksUnhealthy": 0, | ||
"deployments": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
[ | ||
{ | ||
"affectedApps": [ | ||
"/test/service/srv1", | ||
"/test/db/mongo1", | ||
"/test/frontend/app1" | ||
], | ||
"currentStep": 2, | ||
"currentActions": [ | ||
{ | ||
"action": "RestartApplication", | ||
"app": "/test/frontend/app1", | ||
"readinessChecks": [ | ||
{ | ||
"lastResponse": { | ||
"body": "{}", | ||
"contentType": "application/json", | ||
"status": 500 | ||
}, | ||
"name": "myReadyCheck", | ||
"ready": false, | ||
"taskId": "test_frontend_app1.c9de6033" | ||
} | ||
] | ||
} | ||
], | ||
"totalSteps": 9, | ||
"id": "2e72dbf1-2b2a-4204-b628-e8bd160945dd", | ||
"steps": [ | ||
[ | ||
{ | ||
"action": "RestartApplication", | ||
"app": "/test/service/srv1" | ||
} | ||
], | ||
[ | ||
{ | ||
"action": "RestartApplication", | ||
"app": "/test/db/mongo1" | ||
} | ||
], | ||
[ | ||
{ | ||
"action": "RestartApplication", | ||
"app": "/test/frontend/app1" | ||
} | ||
], | ||
[ | ||
{ | ||
"action": "KillAllOldTasksOf", | ||
"app": "/test/frontend/app1" | ||
} | ||
], | ||
[ | ||
{ | ||
"action": "KillAllOldTasksOf", | ||
"app": "/test/db/mongo1" | ||
} | ||
], | ||
[ | ||
{ | ||
"action": "KillAllOldTasksOf", | ||
"app": "/test/service/srv1" | ||
} | ||
], | ||
[ | ||
{ | ||
"action": "ScaleApplication", | ||
"app": "/test/service/srv1" | ||
} | ||
], | ||
[ | ||
{ | ||
"action": "ScaleApplication", | ||
"app": "/test/db/mongo1" | ||
} | ||
], | ||
[ | ||
{ | ||
"action": "ScaleApplication", | ||
"app": "/test/frontend/app1" | ||
} | ||
] | ||
], | ||
"version": "2014-07-09T11:14:11.477Z" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# project | ||
from tests.checks.common import AgentCheckTest | ||
from tests.checks.common import Fixtures | ||
|
||
DEPLOYMENT_METRICS_CONFIG = { | ||
'init_config': { | ||
'default_timeout': 5 | ||
}, | ||
'instances': [ | ||
{ | ||
'url': 'http://localhost:8080', | ||
'enable_deployment_metrics': True | ||
} | ||
] | ||
} | ||
|
||
DEFAULT_CONFIG = { | ||
'init_config': { | ||
'default_timeout': 5 | ||
}, | ||
'instances': [ | ||
{ | ||
'url': 'http://localhost:8080' | ||
} | ||
] | ||
} | ||
|
||
def getMetricNames(metrics): | ||
return [metric[0] for metric in metrics] | ||
|
||
class MarathonCheckTest(AgentCheckTest): | ||
CHECK_NAME = 'marathon' | ||
|
||
def test_default_configuration(self): | ||
def side_effect(url, timeout, auth): | ||
if "v2/apps" in url: | ||
return Fixtures.read_json_file("apps.json") | ||
else: | ||
raise Exception("unknown url:" + url) | ||
|
||
self.run_check(DEFAULT_CONFIG, mocks={"get_json": side_effect}) | ||
self.assertMetric('marathon.apps', value=1) | ||
|
||
# deployment-related metrics aren't included by default. | ||
self.assertTrue('marathon.deployments' not in getMetricNames(self.metrics)) | ||
|
||
def test_empty_responses(self): | ||
def side_effect(url, timeout, auth): | ||
if "v2/apps" in url: | ||
return {"apps": []} | ||
else: | ||
raise Exception("unknown url:" + url) | ||
|
||
self.run_check(DEFAULT_CONFIG, mocks={"get_json": side_effect}) | ||
self.assertMetric('marathon.apps', value=0) | ||
|
||
def test_enabled_deployment_metrics(self): | ||
def side_effect(url, timeout, auth): | ||
if "v2/apps" in url: | ||
return Fixtures.read_json_file("apps.json") | ||
elif "v2/deployments" in url: | ||
return Fixtures.read_json_file("deployments.json") | ||
else: | ||
raise Exception("unknown url:" + url) | ||
|
||
self.run_check(DEPLOYMENT_METRICS_CONFIG, mocks={"get_json": side_effect}) | ||
self.assertMetric('marathon.apps', value=1) | ||
self.assertMetric('marathon.deployments', value=1) |