Copilot commented on code in PR #170:
URL: https://github.com/apache/otava/pull/170#discussion_r3837729784
##########
otava/importer.py:
##########
@@ -827,6 +830,90 @@ def fetch_all_metric_names(self, test_conf:
BigQueryTestConfig) -> List[str]:
return [m for m in test_conf.metrics.keys()]
+class InfluxDBImporter(Importer):
+ def __init__(self, influxdb: InfluxDB):
+ self.__influxdb = influxdb
+
+ @staticmethod
+ def __selected_metrics(
+ defined_metrics: Dict[str, InfluxDBMetric], selected_metrics:
Optional[List[str]]
+ ) -> Dict[str, InfluxDBMetric]:
+ if selected_metrics is not None:
+ return {name: defined_metrics[name] for name in selected_metrics}
+ return defined_metrics
+
+ def fetch_data(self, test_conf: TestConfig, selector: DataSelector =
DataSelector()) -> Series:
+ if not isinstance(test_conf, InfluxDBTestConfig):
+ raise ValueError("Expected InfluxDBTestConfig")
+
+ since_time = selector.since_time
+ until_time = selector.until_time
+ if since_time.timestamp() > until_time.timestamp():
+ raise DataImportError(
+ f"Invalid time range:
[{format_timestamp(int(since_time.timestamp()))}, "
+ f"{format_timestamp(int(until_time.timestamp()))}]"
+ )
+
+ metrics = self.__selected_metrics(test_conf.metrics, selector.metrics)
+ query = test_conf.query
+ if "%{BRANCH}" in query:
+ if not selector.branch:
+ raise DataImportError(
+ f"Test {test_conf.name} uses %{{BRANCH}} in query but
--branch was not specified"
+ )
+ branch_literal = "'" + selector.branch.replace("'", "''") + "'"
Review Comment:
InfluxQL does not use SQL's doubled-quote escaping. Its parser requires `\'`
(and backslashes/newlines must also be escaped), so a branch such as the one in
the new test produces two adjacent string literals and the real query fails to
parse. Escape according to the selected query language rather than asserting
the SQL form for both.
This issue also appears on line 884 of the same file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]