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 { 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'; |
|
|
|
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); |
|
} |
|
}
|
|
|