From 1b0c1ab2cf62f464d47bee334cb7c289699f8344 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Wed, 13 Dec 2017 19:26:41 +0100 Subject: [PATCH] Removed literal string interpolation to run on Python 3 less than 3.6 --- prometheus_pgbouncer_exporter/cli.py | 6 +++--- prometheus_pgbouncer_exporter/collector.py | 8 ++++---- tests/test_config.py | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/prometheus_pgbouncer_exporter/cli.py b/prometheus_pgbouncer_exporter/cli.py index e19f8ff..2adce1c 100644 --- a/prometheus_pgbouncer_exporter/cli.py +++ b/prometheus_pgbouncer_exporter/cli.py @@ -48,9 +48,9 @@ def main(): config = Config() try: config.read(args.config) - logging.getLogger().info(f"Config file successfully read from {args.config}") + logging.getLogger().info("Config file successfully read from {file}".format(file=args.config)) except Exception as error: - logging.getLogger().fatal(f"Unable to read config file from {args.config}", extra={"exception": str(error)}) + logging.getLogger().fatal("Unable to read config file from {file}".format(file=args.config), extra={"exception": str(error)}) sys.exit(1) # Register our custom collector @@ -58,7 +58,7 @@ def main(): # Start server start_http_server(config.getExporterPort(), config.getExporterHost()) - logging.getLogger().info(f"Exporter listening on {config.getExporterHost()}:{config.getExporterPort()}") + logging.getLogger().info("Exporter listening on {host}:{port}".format(host=config.getExporterHost(), port=config.getExporterPort())) while not signal_handler.is_shutting_down(): time.sleep(1) diff --git a/prometheus_pgbouncer_exporter/collector.py b/prometheus_pgbouncer_exporter/collector.py index 3d679d2..b0749a6 100644 --- a/prometheus_pgbouncer_exporter/collector.py +++ b/prometheus_pgbouncer_exporter/collector.py @@ -32,7 +32,7 @@ def _instanceMetric(self, data): elif data["type"] is "gauge": return GaugeMetricFamily(data["name"], data["help"], labels=data["labels"].keys()) else: - raise Exception(f"Unsupported metric type: {data['type']}") + raise Exception("Unsupported metric type: {type}".format(type=data['type'])) class PgbouncerMetricsCollector(): @@ -81,7 +81,7 @@ def collect(self): success = False except Exception as error: - logging.getLogger().debug(f"Unable fetch metrics from {self.config.getDsnWithMaskedPassword()}", extra={"exception": str(error)}) + logging.getLogger().debug("Unable fetch metrics from {dsn}".format(dsn=self.config.getDsnWithMaskedPassword()), extra={"exception": str(error)}) success = False finally: @@ -113,7 +113,7 @@ def _exportMetrics(self, results, metricPrefix, mappings, metricLabels, extraLab metrics.append({ "type": mapping["type"], - "name": f"{metricPrefix}{mapping['metric']}", + "name": metricPrefix + mapping['metric'], "value": result[mapping["column"]], "labels": labels, "help": mapping["help"] @@ -147,7 +147,7 @@ def _fetchMetrics(self, conn, query): return cursor.fetchall() except Exception as error: - logging.getLogger().debug(f"Unable run query {query} on {self.config.getDsnWithMaskedPassword()}", extra={"exception": str(error)}) + logging.getLogger().debug("Unable run query {query} on {dsn}".format(query=query, dsn=self.config.getDsnWithMaskedPassword()), extra={"exception": str(error)}) return False finally: diff --git a/tests/test_config.py b/tests/test_config.py index b39c137..a451721 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -14,7 +14,7 @@ def testShouldRaiseErrorOnUnexistingFile(self): def testShouldSupportAnEmptyConfigFile(self): config = Config() - config.read(f"{CURR_DIR}/fixtures/config-empty.yml") + config.read(CURR_DIR + "/fixtures/config-empty.yml") self.assertEqual(config.getExporterHost(), "127.0.0.1") self.assertEqual(config.getExporterPort(), 9100) @@ -22,7 +22,7 @@ def testShouldSupportAnEmptyConfigFile(self): def testShouldParseConfigFileWithOnePgbouncer(self): config = Config() - config.read(f"{CURR_DIR}/fixtures/config-with-one-pgbouncer.yml") + config.read(CURR_DIR + "/fixtures/config-with-one-pgbouncer.yml") self.assertEqual(config.getExporterHost(), "0.0.0.0") self.assertEqual(config.getExporterPort(), 1234) @@ -37,7 +37,7 @@ def testShouldParseConfigFileWithOnePgbouncer(self): def testShouldParseConfigFileWithTwoPgbouncer(self): config = Config() - config.read(f"{CURR_DIR}/fixtures/config-with-two-pgbouncer.yml") + config.read(CURR_DIR + "/fixtures/config-with-two-pgbouncer.yml") self.assertEqual(config.getExporterHost(), "0.0.0.0") self.assertEqual(config.getExporterPort(), 1234) @@ -65,7 +65,7 @@ def testShouldInjectEnvironmentVariablesOnParsing(self): os.environ["TEST_EXTRA_LABEL_VALUE"] = "users-1-1000" config = Config() - config.read(f"{CURR_DIR}/fixtures/config-with-env-vars.yml") + config.read(CURR_DIR + "/fixtures/config-with-env-vars.yml") self.assertEqual(len(config.getPgbouncers()), 1) self.assertEqual(config.getPgbouncers()[0].getDsn(), "postgresql://marco:secret@host:6431/pgbouncer") @@ -80,7 +80,7 @@ def testShouldInjectEnvironmentVariablesOnParsingEvenIfEmpty(self): os.environ["TEST_EXTRA_LABEL_VALUE"] = "users-1-1000" config = Config() - config.read(f"{CURR_DIR}/fixtures/config-with-env-vars.yml") + config.read(CURR_DIR + "/fixtures/config-with-env-vars.yml") self.assertEqual(len(config.getPgbouncers()), 1) self.assertEqual(config.getPgbouncers()[0].getDsn(), "postgresql://marco:@host:6431/pgbouncer") @@ -93,7 +93,7 @@ def testShouldKeepOriginalConfigOnMissingEnvironmentVariables(self): os.environ["TEST_EXTRA_LABEL_VALUE"] = "users-1-1000" config = Config() - config.read(f"{CURR_DIR}/fixtures/config-with-env-vars.yml") + config.read(CURR_DIR + "/fixtures/config-with-env-vars.yml") self.assertEqual(len(config.getPgbouncers()), 1) self.assertEqual(config.getPgbouncers()[0].getDsn(), "postgresql://$(TEST_USERNAME):secret@host:6431/pgbouncer")