Skip to content

Commit 54a17c5

Browse files
authored
Merge pull request #381 from telefonicaid/fix/metrics_by_service_and_subservice
Fix/metrics by service and subservice
2 parents 42f584a + 444e51c commit 54a17c5

File tree

7 files changed

+220
-167
lines changed

7 files changed

+220
-167
lines changed

CONFIG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ IOTAGENT = {
241241

242242
## Metrics
243243

244-
There are an option, that is disabled by default, to obtain a extended metrics report. This is still experimental due to enable it could imply decrease performance.
244+
There are an option, that is disabled by default, to obtain a extended metrics report. This is still experimental due to enable it could imply decrease performance. And implies configure uWSGI to use just one thread by each process (i.e. enabling THREADS = 1 and PROCESS = 8) instead default uWSGI used by orchestrator
245245
[Extended Metrics](https://orchestrator2.docs.apiary.io/#reference/orchestrator/metrics)
246246

247247
```

DOCKER.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Additionally, the following environment variables are available for orchestrator
149149
| PEP_PASSWORD | PEP.password | pep |
150150
| IOTAGENT_USER | IOTAGENT.user | iotagent |
151151
| IOTAGENT_PASSWORD | IOTAGENT.password | iotagent |
152-
152+
| ORC_EXTENDED_METRICS | ORC_EXTENDED_METRICS | false (experimental) |
153153

154154

155155
## Build the image

bin/orchestrator-entrypoint.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
[[ "${IOTAGENT_USER}" == "" ]] && export IOTAGENT_USER=iotagent
6868
[[ "${IOTAGENT_PASSWORD}" == "" ]] && export IOTAGENT_PASSWORD=iotagent
6969

70-
70+
[[ "${ORC_EXTENDED_METRICS}" == "" ]] && export ORC_EXTENDED_METRICS=false
7171

7272
while [[ $# -gt 0 ]]; do
7373
PARAM=`echo $1`
@@ -304,7 +304,6 @@ sed -i ':a;N;$!ba;s/IOTAGENT = {[A-Za-z0-9,=@.\-\/\"\n: ]*}/IOTAGENT = { \
304304
}/g' /opt/orchestrator/settings/dev.py
305305

306306

307-
308307
if [ "$DEBUG_LEVEL" ]; then
309308
echo "
310309
LOGGING['handlers']['console']['level'] = '$DEBUG_LEVEL'
@@ -315,6 +314,12 @@ LOGGING['loggers']['orchestrator_core']['level'] = '$DEBUG_LEVEL'
315314
fi
316315

317316

317+
if [ "$ORC_EXTENDED_METRICS" == "true" ]; then
318+
echo "
319+
ORC_EXTENDED_METRICS = True
320+
" >> /opt/orchestrator/settings/dev.py
321+
fi
322+
318323
# Wait until Keystone and Keypass are up
319324
while ! nc -zvw10 $KEYSTONE_HOST $KEYSTONE_PORT ; do sleep 10; done
320325
while ! nc -zvw10 $KEYPASS_HOST $KEYPASS_PORT ; do sleep 10; done

src/orchestrator/api/stats.py

Lines changed: 185 additions & 137 deletions
Large diffs are not rendered by default.

src/orchestrator/common/util.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import requests
3030
import logging
3131
import time
32+
import http.client
3233
from settings import dev as settings
3334

3435
class RestOperations(object):
@@ -271,17 +272,26 @@ def collectOutgoingMetrics(self, service_start, data_request, headers_request, r
271272
transactionError = False
272273
if response.code not in [200, 201, 204]:
273274
transactionError = True
274-
data_response = response.msg
275275
if transactionError:
276-
self.sum["outgoingTransactions"] += 1
277-
else:
278276
self.sum["outgoingTransactionErrors"] += 1
279-
self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request)) + len(str(headers_request))
280-
# Check headers
281-
self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response)) + len(str(response.headers.headers)) if 'headers' in response and 'headers' in response.headers else 0
277+
else:
278+
self.sum["outgoingTransactions"] += 1
279+
280+
try:
281+
self.sum["outgoingTransactionRequestSize"] += len(str(data_request)) + len(str(headers_request))
282+
except Exception as ex:
283+
self.logger.warn("ERROR collecting outgoingTransactionRequestSize: %s data_request %s headers_request %s", ex, str(data_request), str(headers_request))
284+
try:
285+
if isinstance(response, http.client.HTTPResponse) and hasattr(response, 'getheader'):
286+
inc = response.getheader("Content-Length")
287+
if inc is not None:
288+
self.sum["outgoingTransactionResponseSize"] += int(inc)
289+
except Exception as ex:
290+
self.logger.warn("ERROR collecting outgoingTransactionResponseSize: %s response %s", ex, str(response))
282291
self.sum["serviceTimeTotal"] += (service_stop - service_start)
292+
283293
except Exception as ex:
284-
self.logger.warn("ERROR collecting outgoing metrics %s", ex)
294+
self.logger.warn("ERROR collecting outgoing metrics: %s", ex)
285295

286296
def getOutgoingMetrics(self):
287297
return self.sum

src/orchestrator/core/flow/base.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#
2424
import logging
2525
import uuid
26+
from functools import reduce
2627

2728
from orchestrator.core.keystone import IdMKeystoneOperations as IdMOperations
2829
from orchestrator.core.keypass import AccCKeypassOperations as AccCOperations
@@ -252,15 +253,14 @@ def ensure_subservice_name(self, USER_TOKEN, SERVICE_ID, SUBSERVICE_ID,
252253

253254

254255
def get_extended_token(self, USER_TOKEN):
255-
token_extended = USER_TOKEN
256+
token_extended = {
257+
"token": USER_TOKEN
258+
}
256259
if USER_TOKEN:
257260
try:
258261
token_detail = self.idm.getTokenDetail(USER_TOKEN)
262+
token_extended["user"] = token_detail['token']['user']['name']
259263

260-
token_extended = {
261-
"token": USER_TOKEN,
262-
"user": token_detail['token']['user']['name']
263-
}
264264
# Include service scope if available
265265
if 'domain' in token_detail['token']['user']:
266266
token_extended['domain'] = \
@@ -273,10 +273,8 @@ def get_extended_token(self, USER_TOKEN):
273273

274274
except Exception as ex:
275275
# Probably expired?
276-
token_extended = {
277-
"token": USER_TOKEN,
278-
"error": str(ex)
279-
}
276+
token_extended["error"] = str(ex)
277+
280278
return token_extended
281279

282280
def collectComponentMetrics(self):
@@ -290,9 +288,9 @@ def collectComponentMetrics(self):
290288
all.append(self.cb.CBRestOperations.getOutgoingMetrics())
291289
all.append(self.perseo.PerseoRestOperations.getOutgoingMetrics())
292290
# TODO: Take care of the following operation takes too much time
293-
self.sum = reduce(lambda x, y: dict((k, v + y[k]) for k, v in x.iteritems()), all)
291+
self.sum = reduce(lambda x, y: {k: v + y[k] for k, v in x.items()}, all)
294292
except Exception as ex:
295-
self.logger.error("ERROR collecting component metrics %s", ex)
293+
self.logger.error("ERROR collecting component metrics: %s", ex)
296294

297295
def getFlowMetrics(self):
298296
return self.sum

src/wsgi.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@
1717

1818
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "orchestrator.settings.dev")
1919

20-
from multiprocessing import Manager
21-
manager = Manager()
22-
shared_data = manager.dict()
23-
24-
from django.conf import settings
25-
settings.SHARED_DATA = shared_data
26-
27-
2820
# This application object is used by any WSGI server configured to use this
2921
# file. This includes Django's development server, if the WSGI_APPLICATION
3022
# setting points here.

0 commit comments

Comments
 (0)