Skip to content

Commit

Permalink
Removed literal string interpolation to run on Python 3 less than 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Pracucci committed Dec 13, 2017
1 parent 7794ad2 commit 1b0c1ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions prometheus_pgbouncer_exporter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ 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
REGISTRY.register(PgbouncersMetricsCollector(config.getPgbouncers()))

# 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)
Expand Down
8 changes: 4 additions & 4 deletions prometheus_pgbouncer_exporter/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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)
self.assertEqual(config.getPgbouncers(), [])

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)
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 1b0c1ab

Please sign in to comment.