|
|
|
import { InfluxdbMetric } from './influxdb_metric';
|
|
|
|
import { GraphiteMetric } from './graphite_metric';
|
|
|
|
import { DatasourceConnector, DatasourceType } from './metric';
|
|
|
|
import { PrometheusMetric } from './prometheus_metric';
|
|
|
|
import { PostgresMetric } from './postgres_metric';
|
|
|
|
import { ElasticsearchMetric } from './elasticsearch_metric';
|
|
|
|
import { MysqlMetric } from './mysql_metric';
|
|
|
|
|
|
|
|
import { QueryConfig } from '../models/query_config';
|
|
|
|
|
|
|
|
|
|
|
|
export function connectorFactory(
|
|
|
|
queryConfig: QueryConfig,
|
|
|
|
): DatasourceConnector {
|
|
|
|
const classMap = {
|
|
|
|
[DatasourceType.INFLUXDB]: InfluxdbMetric,
|
|
|
|
[DatasourceType.GRAPHITE]: GraphiteMetric,
|
|
|
|
[DatasourceType.PROMETHEUS]: PrometheusMetric,
|
|
|
|
[DatasourceType.POSTGRES]: PostgresMetric,
|
|
|
|
[DatasourceType.ELASTICSEARCH]: ElasticsearchMetric,
|
|
|
|
[DatasourceType.MYSQL]: MysqlMetric,
|
|
|
|
};
|
|
|
|
const datasource = queryConfig.datasource;
|
|
|
|
const targets = queryConfig.targets;
|
|
|
|
if(classMap[datasource.type] === undefined) {
|
|
|
|
console.error(`Datasources of type ${datasource.type} are not supported currently`);
|
|
|
|
throw new Error(`Datasources of type ${datasource.type} are not supported currently`);
|
|
|
|
} else {
|
|
|
|
return new classMap[datasource.type](datasource, targets);
|
|
|
|
}
|
|
|
|
}
|