Skip to content

Commit

Permalink
Fix Fake Health API
Browse files Browse the repository at this point in the history
- Add region samples
- Add missing data
  • Loading branch information
boris-42 committed Dec 6, 2016
1 parent cb1068b commit c334ae7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
13 changes: 9 additions & 4 deletions ceagle/api_fake_data/fake_status.py
Expand Up @@ -60,7 +60,7 @@ def generate_timestamps(period):


def generate_values(period_or_timestamps,
ratio=1, null_result_probability=20):
ratio=1, null_result_probability=20, integer=False):
if type(period_or_timestamps) == list:
timestamps = period_or_timestamps
else:
Expand All @@ -72,7 +72,10 @@ def generate_values(period_or_timestamps,
if random.randint(1, 100) <= null_result_probability:
data.append([ts, None])
else:
value = base.randnum(.7, 1) * ratio
if not integer:
value = base.randnum(.7, 1) * ratio
else:
value = random.randint(1, 1000)
data.append([ts, value])
data_avg.append(value)
avg = round(sum(data_avg) / len(data_avg), 3)
Expand All @@ -83,15 +86,17 @@ def generate_service_data(period, service):
if service == "health":
fci_data = generate_values(period)[0]
time_data = generate_values(period)[0]
size_data = generate_values(period, 50)[0]
size_data = generate_values(period, 50, integer=True)[0]
count_data = generate_values(period, 50, integer=True)[0]
return {
"fci": random.randint(0, 100) * 0.01,
"response_time": base.randnum(.1, 2.5),
"response_size": random.randint(2000, 5000),
"api_calls_count": random.randint(200, 500),
"fci_data": fci_data,
"response_time_data": time_data,
"repsonse_size_data": size_data
"repsonse_size_data": size_data,
"api_calls_count_data": count_data
}

elif service == "performance":
Expand Down
2 changes: 1 addition & 1 deletion raml/api.raml
Expand Up @@ -70,7 +70,7 @@ mediaType: application/json
body:
application/json:
schema: schemas/200.json
example: !include response_examples/200/status_health.json
example: !include response_examples/200/status_region_health.json
404:
body:
application/json:
Expand Down
13 changes: 10 additions & 3 deletions raml/response_examples/200/status_health.json
Expand Up @@ -12,21 +12,28 @@
["2016-09-16T01:00", 0.7],
["2016-09-16T02:00", 1.0],
["2016-09-16T03:00", 0.95],
["2016-09-16T04:00", 1.0],
["2016-09-16T04:00", 1.0]
],
"response_time_data": [
["2016-09-16T01:00", 0.9],
["2016-09-16T02:00", 0.8],
["2016-09-16T03:00", 1.0],
["2016-09-16T04:00", 0.95],
["2016-09-16T05:00", 1.0],
["2016-09-16T05:00", 1.0]
],
"repsonse_size_data": [
["2016-09-16T01:00", 100],
["2016-09-16T02:00", 250],
["2016-09-16T03:00", 300],
["2016-09-16T04:00", 400],
["2016-09-16T05:00", 500],
["2016-09-16T05:00", 500]
],
"api_calls_count_data": [
["2016-09-16T01:00", 100],
["2016-09-16T02:00", 250],
["2016-09-16T03:00", 300],
["2016-09-16T04:00", 400],
["2016-09-16T05:00", 500]
]
}
}
Expand Down
40 changes: 40 additions & 0 deletions raml/response_examples/200/status_region_health.json
@@ -0,0 +1,40 @@
{
"period": "week",

"health": {
"keystone": {
"fci": 0.9,
"response_time": 100.43,
"response_size": 234343,
"api_calls_count": 5,
"fci_data": [
["2016-09-16T01:00", 0.9],
["2016-09-16T01:00", 0.7],
["2016-09-16T02:00", 1.0],
["2016-09-16T03:00", 0.95],
["2016-09-16T04:00", 1.0]
],
"response_time_data": [
["2016-09-16T01:00", 0.9],
["2016-09-16T02:00", 0.8],
["2016-09-16T03:00", 1.0],
["2016-09-16T04:00", 0.95],
["2016-09-16T05:00", 1.0]
],
"repsonse_size_data": [
["2016-09-16T01:00", 100],
["2016-09-16T02:00", 250],
["2016-09-16T03:00", 300],
["2016-09-16T04:00", 400],
["2016-09-16T05:00", 500]
],
"api_calls_count_data": [
["2016-09-16T01:00", 100],
["2016-09-16T02:00", 250],
["2016-09-16T03:00", 300],
["2016-09-16T04:00", 400],
["2016-09-16T05:00", 500]
]
}
}
}

0 comments on commit c334ae7

Please sign in to comment.