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.
31 lines
1.2 KiB
31 lines
1.2 KiB
import { InfluxdbConnector } from './influxdb'; |
|
import { GraphiteConnector } from './graphite'; |
|
import { DatasourceConnector, DatasourceType } from '.'; |
|
import { PrometheusConnector } from './prometheus'; |
|
import { PostgresConnector } from './postgres'; |
|
import { ElasticsearchConnector } from './elasticsearch'; |
|
import { MysqlConnector } from './mysql'; |
|
|
|
import { QueryConfig } from '../models/query_config'; |
|
|
|
|
|
export function connectorFactory( |
|
queryConfig: QueryConfig, |
|
): DatasourceConnector { |
|
const classMap = { |
|
[DatasourceType.INFLUXDB]: InfluxdbConnector, |
|
[DatasourceType.GRAPHITE]: GraphiteConnector, |
|
[DatasourceType.PROMETHEUS]: PrometheusConnector, |
|
[DatasourceType.POSTGRES]: PostgresConnector, |
|
[DatasourceType.ELASTICSEARCH]: ElasticsearchConnector, |
|
[DatasourceType.MYSQL]: MysqlConnector, |
|
}; |
|
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); |
|
} |
|
}
|
|
|