Skip to content

Commit

Permalink
Merge pull request #221 from Helene/fix_err_msg
Browse files Browse the repository at this point in the history
Fix broken ERR messages
  • Loading branch information
Helene authored May 30, 2024
2 parents 422cc62 + 385154b commit a948cfa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions source/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import copy
import analytics
from queryHandler.Query import Query
from messages import MSG
from messages import MSG, ERR
from collections import defaultdict
from typing import Optional, Any, List
from threading import Thread
Expand Down Expand Up @@ -216,7 +216,7 @@ def get_zimon_query(self):
if not self.metricsaggr and not self.sensor:
self.logger.error(MSG['QueryError'].
format('Missing metric or sensor name'))
raise cherrypy.HTTPError(400, MSG[400])
raise cherrypy.HTTPError(400, ERR[400])

if self.metricsaggr:
for key, value in self.metricsaggr.items():
Expand Down
6 changes: 3 additions & 3 deletions source/confgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def GET(self, **params):

conn = cherrypy.request.headers.get('Host').split(':')
if int(conn[1]) != int(self.attr.get('prometheus')):
self.logger.error(MSG['EndpointNotSupportedForPort'].
format(cherrypy.request.script_name, str(conn[1])))
raise cherrypy.HTTPError(400, ERR[400])

# generate prometheus.yml
Expand All @@ -122,9 +124,7 @@ def GET(self, **params):

else:
self.logger.error(MSG['EndpointNotSupported'].format(cherrypy.request.script_name))
raise cherrypy.HTTPError(400,
MSG['EndpointNotSupported'].format(
cherrypy.request.script_name))
raise cherrypy.HTTPError(400, ERR[400])

del cherrypy.response.headers['Allow']
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
Expand Down
1 change: 1 addition & 0 deletions source/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'InconsistentParams': 'Received parameters {} inconsistent with request parameters {}',
'SensorDisabled': 'Sensor for metric {} is disabled',
'EndpointNotSupported': 'Endpoint {} you try to access is not supported',
'EndpointNotSupportedForPort': 'Endpoint {} is not supported for port {}',
'NoData': 'Empty results received', # Please check the pmcollector is properly configured and running.
'NoSensorConfigData': 'No sensor configuration data parsed',
'NoDataStartNextAttempt': 'No Metadata results received from the pmcollector. Start retry attempt {} in 60s (MAX_ATTEMPTS_COUNT:{})',
Expand Down
4 changes: 2 additions & 2 deletions source/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from queryHandler.Topo import Topo
from queryHandler import SensorConfig
from utils import execution_time
from messages import MSG
from messages import ERR, MSG
from metaclasses import Singleton
from time import sleep

Expand Down Expand Up @@ -186,7 +186,7 @@ def update(self, refresh_all=False):
self.__metaData = Topo(self.qh.getTopology())
if not (self.metaData and self.metaData.topo):
self.logger.error(MSG['NoData']) # Please check the pmcollector is properly configured and running.
raise cherrypy.HTTPError(404, MSG[404])
raise cherrypy.HTTPError(404, ERR[404])
self.logger.details(MSG['MetaSuccess'])
self.logger.debug(MSG['ReceivAttrValues'].format('parents', ", ".join(self.metaData.allParents)))
return ({'msg': MSG['MetaSuccess']})
11 changes: 9 additions & 2 deletions source/opentsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ def GET(self, **params):

conn = cherrypy.request.headers.get('Host').split(':')
if int(conn[1]) != int(self.port):
raise cherrypy.HTTPError(400, MSG[400])
self.logger.error(MSG['EndpointNotSupportedForPort'].
format(cherrypy.request.script_name, str(conn[1])))
raise cherrypy.HTTPError(400, ERR[400])

# /api/suggest
if 'suggest' in cherrypy.request.script_name:
Expand All @@ -307,6 +309,11 @@ def GET(self, **params):
supportedFilters['pm_filter'] = filterDesc
resp = supportedFilters

else:
self.logger.error(MSG['EndpointNotSupported'].
format(cherrypy.request.script_name))
raise cherrypy.HTTPError(400, ERR[400])

del cherrypy.response.headers['Allow']
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
# cherrypy.response.headers['Content-Type'] = 'application/json'
Expand All @@ -327,7 +334,7 @@ def POST(self):
jreq = cherrypy.request.json
if jreq.get('queries') is None:
self.logger.error(MSG['QueryError'].format('empty'))
raise cherrypy.HTTPError(400, MSG[400])
raise cherrypy.HTTPError(400, ERR[400])

return self.query(jreq)

Expand Down
13 changes: 7 additions & 6 deletions source/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import cherrypy
import json
import analytics
from messages import MSG
from messages import ERR, MSG
from typing import Optional
from cherrypy.process.plugins import Monitor
from collector import SensorCollector, QueryPolicy
Expand Down Expand Up @@ -151,7 +151,9 @@ def GET(self, **params):

conn = cherrypy.request.headers.get('Host').split(':')
if int(conn[1]) != int(self.port):
raise cherrypy.HTTPError(400, MSG[400])
self.logger.error(MSG['EndpointNotSupportedForPort'].
format(cherrypy.request.script_name, str(conn[1])))
raise cherrypy.HTTPError(400, ERR[400])

if self.endpoints and self.endpoints.get(cherrypy.request.script_name,
None):
Expand All @@ -169,10 +171,9 @@ def GET(self, **params):
return resString

else:
self.logger.error(MSG['EndpointNotSupported'].format(sensor))
raise cherrypy.HTTPError(400,
MSG['EndpointNotSupported'].format(
cherrypy.request.script_name))
self.logger.error(MSG['EndpointNotSupported'].
format(cherrypy.request.script_name))
raise cherrypy.HTTPError(400, ERR[400])

del cherrypy.response.headers['Allow']
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
Expand Down

0 comments on commit a948cfa

Please sign in to comment.