config_ctrl.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import _ from 'lodash';
  2. import { ElasticsearchOptions } from './types';
  3. import { DataSourceInstanceSettings } from '@grafana/ui';
  4. import { getMaxConcurrenShardRequestOrDefault } from './datasource';
  5. export class ElasticConfigCtrl {
  6. static templateUrl = 'public/app/plugins/datasource/elasticsearch/partials/config.html';
  7. current: DataSourceInstanceSettings<ElasticsearchOptions>;
  8. /** @ngInject */
  9. constructor($scope: any) {
  10. this.current.jsonData.timeField = this.current.jsonData.timeField || '@timestamp';
  11. this.current.jsonData.esVersion = this.current.jsonData.esVersion || 5;
  12. const defaultMaxConcurrentShardRequests = this.current.jsonData.esVersion >= 70 ? 5 : 256;
  13. this.current.jsonData.maxConcurrentShardRequests =
  14. this.current.jsonData.maxConcurrentShardRequests || defaultMaxConcurrentShardRequests;
  15. this.current.jsonData.logMessageField = this.current.jsonData.logMessageField || '';
  16. this.current.jsonData.logLevelField = this.current.jsonData.logLevelField || '';
  17. }
  18. indexPatternTypes: any = [
  19. { name: 'No pattern', value: undefined },
  20. { name: 'Hourly', value: 'Hourly', example: '[logstash-]YYYY.MM.DD.HH' },
  21. { name: 'Daily', value: 'Daily', example: '[logstash-]YYYY.MM.DD' },
  22. { name: 'Weekly', value: 'Weekly', example: '[logstash-]GGGG.WW' },
  23. { name: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM' },
  24. { name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' },
  25. ];
  26. esVersions = [
  27. { name: '2.x', value: 2 },
  28. { name: '5.x', value: 5 },
  29. { name: '5.6+', value: 56 },
  30. { name: '6.0+', value: 60 },
  31. { name: '7.0+', value: 70 },
  32. ];
  33. indexPatternTypeChanged() {
  34. if (
  35. !this.current.database ||
  36. this.current.database.length === 0 ||
  37. this.current.database.startsWith('[logstash-]')
  38. ) {
  39. const def: any = _.find(this.indexPatternTypes, {
  40. value: this.current.jsonData.interval,
  41. });
  42. this.current.database = def.example || 'es-index-name';
  43. }
  44. }
  45. versionChanged() {
  46. this.current.jsonData.maxConcurrentShardRequests = getMaxConcurrenShardRequestOrDefault(this.current.jsonData);
  47. }
  48. }