Skip to content

Commit

Permalink
expand to materialization and credentials servers
Browse files Browse the repository at this point in the history
  • Loading branch information
dsschult committed Jan 28, 2025
1 parent 1eb000c commit 435fe83
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
30 changes: 15 additions & 15 deletions iceprod/credentials/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import time

from prometheus_client import Info, start_http_server
import pymongo
import pymongo.errors
import motor.motor_asyncio
Expand All @@ -16,9 +17,9 @@
from tornado.web import RequestHandler as TornadoRequestHandler
from wipac_dev_tools import from_environment

from iceprod import __version__ as version_string
from iceprod.rest.auth import authorization
from iceprod.rest.base_handler import IceProdRestConfig, APIBase
from iceprod.server.module import FakeStatsClient, StatsClientIgnoreErrors
from iceprod.server.util import nowstr, datetime2str
from .service import RefreshService, get_expiration, is_expired

Expand Down Expand Up @@ -427,8 +428,7 @@ def __init__(self):
'DB_URL': 'mongodb://localhost/creds',
'DB_TIMEOUT': 60,
'DB_WRITE_CONCERN': 1,
'STATSD_ADDRESS': '',
'STATSD_PREFIX': 'credentials',
'PROMETHEUS_PORT': 0,
'CI_TESTING': '',
}
config = from_environment(default_config)
Expand All @@ -453,17 +453,8 @@ def __init__(self):
else:
raise RuntimeError('OPENID_URL not specified, and CI_TESTING not enabled!')

statsd = FakeStatsClient()
if config['STATSD_ADDRESS']:
try:
addr = config['STATSD_ADDRESS']
port = 8125
if ':' in addr:
addr,port = addr.split(':')
port = int(port)
statsd = StatsClientIgnoreErrors(addr, port=port, prefix=config['STATSD_PREFIX'])
except Exception:
logger.warning('failed to connect to statsd: %r', config['STATSD_ADDRESS'], exc_info=True)
# enable monitoring
self.prometheus_port = config['PROMETHEUS_PORT'] if config['PROMETHEUS_PORT'] > 0 else None

logging_url = config["DB_URL"].split('@')[-1] if '@' in config["DB_URL"] else config["DB_URL"]
logging.info(f'DB: {logging_url}')
Expand Down Expand Up @@ -506,7 +497,7 @@ def __init__(self):
)
self.refresh_service_task = None

kwargs = IceProdRestConfig(rest_config, statsd=statsd, database=self.db)
kwargs = IceProdRestConfig(rest_config, database=self.db)
kwargs['refresh_service'] = self.refresh_service
kwargs['rest_client'] = rest_client

Expand All @@ -522,6 +513,15 @@ def __init__(self):
self.server = server

async def start(self):
if self.prometheus_port:
logging.info("starting prometheus on {}", self.prometheus_port)
start_http_server(self.prometheus_port)
i = Info('iceprod', 'IceProd information')
i.info({
'version': version_string,
'type': 'api',
})

for collection in self.indexes:
existing = await self.db[collection].index_information()
for name in self.indexes[collection]:
Expand Down
28 changes: 14 additions & 14 deletions iceprod/materialization/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
import uuid

from prometheus_client import Info, start_http_server
import pymongo
import pymongo.errors
import motor.motor_asyncio
Expand All @@ -18,9 +19,9 @@
from tornado.web import RequestHandler as TornadoRequestHandler
from wipac_dev_tools import from_environment

from iceprod import __version__ as version_string
from iceprod.rest.auth import authorization, attr_auth
from iceprod.rest.base_handler import IceProdRestConfig, APIBase
from iceprod.server.module import FakeStatsClient, StatsClientIgnoreErrors
from iceprod.server.util import nowstr, datetime2str
from .service import MaterializationService

Expand Down Expand Up @@ -279,8 +280,7 @@ def __init__(self):
'DB_URL': 'mongodb://localhost/datasets',
'DB_TIMEOUT': 60,
'DB_WRITE_CONCERN': 1,
'STATSD_ADDRESS': '',
'STATSD_PREFIX': 'rest_api',
'PROMETHEUS_PORT': 0,
'CI_TESTING': '',
}
config = from_environment(default_config)
Expand All @@ -305,17 +305,8 @@ def __init__(self):
else:
raise RuntimeError('OPENID_URL not specified, and CI_TESTING not enabled!')

statsd = FakeStatsClient()
if config['STATSD_ADDRESS']:
try:
addr = config['STATSD_ADDRESS']
port = 8125
if ':' in addr:
addr,port = addr.split(':')
port = int(port)
statsd = StatsClientIgnoreErrors(addr, port=port, prefix=config['STATSD_PREFIX'])
except Exception:
logger.warning('failed to connect to statsd: %r', config['STATSD_ADDRESS'], exc_info=True)
# enable monitoring
self.prometheus_port = config['PROMETHEUS_PORT'] if config['PROMETHEUS_PORT'] > 0 else None

logging_url = config["DB_URL"].split('@')[-1] if '@' in config["DB_URL"] else config["DB_URL"]
logging.info(f'DB: {logging_url}')
Expand Down Expand Up @@ -369,6 +360,15 @@ def __init__(self):
self.server = server

async def start(self):
if self.prometheus_port:
logging.info("starting prometheus on {}", self.prometheus_port)
start_http_server(self.prometheus_port)
i = Info('iceprod', 'IceProd information')
i.info({
'version': version_string,
'type': 'api',
})

for collection in self.indexes:
existing = await self.db[collection].index_information()
for name in self.indexes[collection]:
Expand Down

0 comments on commit 435fe83

Please sign in to comment.