open method
- IContext? context
override
Opens the component.
context
(optional) a context to trace execution through call chain. Return Future that receives null no errors occured. Throws error
Implementation
@override
Future open(IContext? context) async {
if (_opened) {
return null;
}
if (!_pushEnabled) {
return null;
}
ConfigParams? connection;
try {
connection = await _connectionResolver.resolve(context);
// ignore: unnecessary_null_comparison
if (connection == null) {
throw Exception('Empty config.');
}
} catch (err) {
_client = null;
_logger.warn(
context, 'Connection to Prometheus server is not configured: $err');
return null;
}
var job = _source ?? 'unknown';
var instance = _instance ?? Platform.localHostname;
_requestRoute = '/metrics/job/$job/instance/$instance';
_uri = connection.getAsString('uri');
_client = http.Client();
_opened = true;
}