You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.2 KiB
32 lines
1.2 KiB
2 years ago
|
import { InfluxdbMetric } from './influxdb';
|
||
|
import { GraphiteMetric } from './graphite';
|
||
|
import { DatasourceConnector, DatasourceType } from '.';
|
||
|
import { PrometheusMetric } from './prometheus';
|
||
|
import { PostgresMetric } from './postgres';
|
||
|
import { ElasticsearchMetric } from './elasticsearch';
|
||
|
import { MysqlMetric } from './mysql';
|
||
4 years ago
|
|
||
2 years ago
|
import { QueryConfig } from '../models/query_config';
|
||
4 years ago
|
|
||
2 years ago
|
|
||
|
export function connectorFactory(
|
||
|
queryConfig: QueryConfig,
|
||
|
): DatasourceConnector {
|
||
2 years ago
|
const classMap = {
|
||
|
[DatasourceType.INFLUXDB]: InfluxdbMetric,
|
||
|
[DatasourceType.GRAPHITE]: GraphiteMetric,
|
||
|
[DatasourceType.PROMETHEUS]: PrometheusMetric,
|
||
|
[DatasourceType.POSTGRES]: PostgresMetric,
|
||
|
[DatasourceType.ELASTICSEARCH]: ElasticsearchMetric,
|
||
|
[DatasourceType.MYSQL]: MysqlMetric,
|
||
4 years ago
|
};
|
||
2 years ago
|
const datasource = queryConfig.datasource;
|
||
|
const targets = queryConfig.targets;
|
||
4 years ago
|
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 {
|
||
2 years ago
|
return new classMap[datasource.type](datasource, targets);
|
||
4 years ago
|
}
|
||
|
}
|