iguazio.dashboard-controls 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iguazio.dashboard-controls",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/js/iguazio.dashboard-controls.js",
5
5
  "description": "Collection of resources (such as CSS styles, fonts and images) and AngularJs 1.x components and services to share among different Iguazio repos.",
6
6
  "repository": {
@@ -4,8 +4,9 @@
4
4
  angular.module('iguazio.dashboard-controls')
5
5
  .factory('ControlPanelLogsDataService', ControlPanelLogsDataService);
6
6
 
7
- function ControlPanelLogsDataService($q, lodash, ElasticsearchService) {
7
+ function ControlPanelLogsDataService($q, lodash, ElasticsearchService, ElasticSearchDataService) {
8
8
  return {
9
+ collectLogs: collectLogs,
9
10
  entriesPaginated: search,
10
11
  logsPaginated: logsWidthReplicas
11
12
  };
@@ -52,8 +53,8 @@
52
53
  if (queryParams.timeFrame) {
53
54
  searchFrom = 'now-' + queryParams.timeFrame;
54
55
  } else {
55
- searchFrom = queryParams.customTimeFrame.from
56
- searchTo = lodash.get(queryParams, 'customTimeFrame.to', 'now')
56
+ searchFrom = lodash.get(queryParams, 'customTimeFrame.from', '1970-01-01T00:00:00Z');
57
+ searchTo = lodash.get(queryParams, 'customTimeFrame.to', 'now');
57
58
  }
58
59
  }
59
60
 
@@ -113,6 +114,10 @@
113
114
  });
114
115
  }
115
116
 
117
+ if (queryParams.trackTotalHits) {
118
+ config.track_total_hits = true;
119
+ }
120
+
116
121
  return ElasticsearchService.search(config)
117
122
  .then(function (response) {
118
123
  // Saved log entry can be found in `_source` property
@@ -140,6 +145,51 @@
140
145
  });
141
146
  }
142
147
 
148
+ /**
149
+ * Collects all the logs using chunks, and saved them as an array of strings.
150
+ * @returns {Promise.<Array.<Object>>} a promise resolving to an array of logs.
151
+ */
152
+ function collectLogs(query) {
153
+ var keepAlive = '5m';
154
+ var size = 10000;
155
+ var downloadLogsData = [];
156
+ var createPitConfig = {
157
+ index: 'filebeat*',
158
+ keepAlive: keepAlive
159
+ };
160
+
161
+ return ElasticSearchDataService.createPit(createPitConfig).then(function (pitId) {
162
+ return getNextPitLogs(pitId, null);
163
+ });
164
+
165
+ function getNextPitLogs(pitId, searchAfter) {
166
+ return ElasticSearchDataService.getNextPitLogs(size, query, keepAlive, pitId, searchAfter).then(function (response) {
167
+ var hits = response.hits.hits;
168
+
169
+ if (hits.length > 0) {
170
+ var lastHit = lodash.last(hits);
171
+
172
+ downloadLogsData = downloadLogsData.concat(prepareLogs(hits));
173
+
174
+ return getNextPitLogs(response.pit_id, lastHit.sort)
175
+ } else {
176
+ return downloadLogsData;
177
+ }
178
+ }).catch(function (error) {
179
+ throw error;
180
+ });
181
+ }
182
+
183
+ function prepareLogs(logs) {
184
+ return logs.map(function (logData) {
185
+ var log = lodash.get(logData, '_source', {});
186
+
187
+ return log['@timestamp'] + ' ' + log.name + ' (' + log.level + ') ' +
188
+ lodash.get(log, 'message', '') + ' ' + JSON.stringify(lodash.get(log, 'more', {}));
189
+ });
190
+ }
191
+ }
192
+
143
193
  /**
144
194
  * Mocks the real search function without the need for a running Elasticsearch service, for development
145
195
  * purposes.
@@ -195,7 +245,7 @@
195
245
  logs.replicas = replicas;
196
246
  }
197
247
 
198
- console.info(queryParams);
248
+ // console.info(queryParams);
199
249
 
200
250
  return $q.when(logs);
201
251
  }
@@ -31,8 +31,9 @@ such restriction.
31
31
  function NclVersionExecutionLogController(lodash, $interval, i18next, $i18next, $rootScope, moment, ConfigService,
32
32
  ControlPanelLogsDataService, ExportService, LoginService,PaginationService) {
33
33
  var ctrl = this;
34
-
35
34
  var lng = i18next.language;
35
+ var MAX_DOWNLOAD_LOGS = 2000000;
36
+
36
37
  var refreshInterval = null;
37
38
  var initialTimeRange = {
38
39
  from: null,
@@ -51,6 +52,7 @@ such restriction.
51
52
  }
52
53
  };
53
54
 
55
+ ctrl.downloadButtonIsHidden = true;
54
56
  ctrl.isSplashShowed = {
55
57
  value: false
56
58
  };
@@ -67,6 +69,7 @@ such restriction.
67
69
  }
68
70
  };
69
71
  ctrl.datePreset = initialDatePreset;
72
+ ctrl.logsAreDownloading = false;
70
73
  ctrl.timeRange = initialTimeRange;
71
74
  ctrl.searchStates = {};
72
75
  ctrl.selectedReplicas = [];
@@ -164,7 +167,7 @@ such restriction.
164
167
  ctrl.$onDestroy = onDestroy;
165
168
 
166
169
  ctrl.applyFilters = applyFilters;
167
- // ctrl.downloadLogFiles = downloadLogFiles;
170
+ ctrl.downloadLogFiles = downloadLogFiles;
168
171
  ctrl.onCheckboxChange = onCheckboxChange;
169
172
  ctrl.onRefreshRateChange = onRefreshRateChange;
170
173
  ctrl.onTimeRangeChange = onTimeRangeChange;
@@ -189,6 +192,12 @@ such restriction.
189
192
 
190
193
  ctrl.page.size = ctrl.perPageValues[0].id;
191
194
 
195
+ ControlPanelLogsDataService.logsPaginated(0, 100, { query: generateDefaultQuery(), trackTotalHits: true })
196
+ .then(function (logs) {
197
+ if (logs.length > 0) {
198
+ ctrl.downloadButtonIsHidden = logs.total_logs_count >= MAX_DOWNLOAD_LOGS;
199
+ }
200
+ });
192
201
  applyFilters();
193
202
  }
194
203
 
@@ -213,18 +222,18 @@ such restriction.
213
222
  searchWithParams(0, ctrl.page.size);
214
223
  }
215
224
 
216
- // /**
217
- // * Downloads log to the file
218
- // */
219
- // function downloadLogFiles() {
220
- // ExportService.exportLogs(prepareLogs(), ctrl.version.metadata.name);
221
- //
222
- // function prepareLogs() {
223
- // return ctrl.logs.map(function (log) {
224
- // return log['@timestamp'] + ' ' + log.name + ' (' + log.level + ') ' + log.message + ' ' + log.more;
225
- // });
226
- // }
227
- // }
225
+ /**
226
+ * Downloads log to the file
227
+ */
228
+ function downloadLogFiles() {
229
+ stopAutoUpdate();
230
+
231
+ return ControlPanelLogsDataService.collectLogs(generateDefaultQuery())
232
+ .then(function (response) {
233
+ ExportService.exportLogs(response, ctrl.version.metadata.name);
234
+ startAutoUpdate();
235
+ });
236
+ }
228
237
 
229
238
  /**
230
239
  * Triggered when search text was changed
@@ -277,7 +286,7 @@ such restriction.
277
286
  function refreshLogs() {
278
287
  startAutoUpdate();
279
288
 
280
- ControlPanelLogsDataService.logsPaginated(ctrl.page.number, ctrl.page.size, queryParams(), true)
289
+ ControlPanelLogsDataService.logsPaginated(ctrl.page.number, ctrl.page.size, queryParams())
281
290
  .then(function (logs) {
282
291
  if (logs.length > 0) {
283
292
  ctrl.logs = lodash.cloneDeep(logs);
@@ -330,13 +339,12 @@ such restriction.
330
339
  return;
331
340
  }
332
341
 
333
- ControlPanelLogsDataService.logsPaginated(ctrl.page.number, ctrl.page.size, queryParamsAutoUpdate(), true)
342
+ ControlPanelLogsDataService.logsPaginated(ctrl.page.number, ctrl.page.size, queryParamsAutoUpdate())
334
343
  .then(function (logs) {
335
344
  if (logs.length > 0) {
336
345
  ctrl.logs = lodash.cloneDeep(logs);
337
346
  ctrl.page.total = logs['total_pages'];
338
347
 
339
- // set lastItemTimeStamp and start autoupdate
340
348
  onChangePageCallback();
341
349
  }
342
350
  });
@@ -412,12 +420,25 @@ such restriction.
412
420
  ctrl.filterQuery = lodash.join(queries, ' AND ');
413
421
  }
414
422
 
423
+ /**
424
+ * Generates query string without additional filters
425
+ */
426
+ function generateDefaultQuery() {
427
+ var queries = ['system-id:"' + ConfigService.systemId + '"', '_exists_:nuclio'];
428
+
429
+ if (!lodash.isEmpty(ctrl.version.metadata.name)) {
430
+ queries.push('name:' + ctrl.version.metadata.name);
431
+ }
432
+ return lodash.join(queries, ' AND ');
433
+ }
434
+
415
435
  /**
416
436
  * Generates query params for ordinary request, for example, when page was changed
417
437
  * @returns {Object}
418
438
  */
419
439
  function queryParams() {
420
440
  return {
441
+ trackTotalHits: true,
421
442
  query: ctrl.filterQuery,
422
443
  timeFrame: ctrl.datePreset,
423
444
  customTimeFrame: ctrl.timeRange
@@ -126,16 +126,17 @@
126
126
  data-refresh="$ctrl.searchWithParams($ctrl.page.number, $ctrl.page.size)">
127
127
  </igz-action-item-refresh>
128
128
  </div>
129
- <!-- <div class="actions-bar-left">-->
130
- <!-- <div class="igz-action-item"-->
131
- <!-- data-ng-click="$ctrl.downloadLogFiles()"-->
132
- <!-- data-uib-tooltip="{{ 'common:DOWNLOAD' | i18next }}"-->
133
- <!-- data-tooltip-placement="bottom"-->
134
- <!-- data-tooltip-popup-delay="300"-->
135
- <!-- data-tooltip-append-to-body="true">-->
136
- <!-- <div class="action-icon igz-icon-download"></div>-->
137
- <!-- </div>-->
138
- <!-- </div>-->
129
+ <div class="actions-bar-left" data-ng-hide="$ctrl.downloadButtonIsHidden">
130
+ <div class="igz-action-item"
131
+ data-ng-click="$ctrl.downloadLogFiles()"
132
+ data-ng-class="{'inactive': $ctrl.logsAreDownloading}"
133
+ data-uib-tooltip="{{ 'common:DOWNLOAD' | i18next }}"
134
+ data-tooltip-placement="bottom"
135
+ data-tooltip-popup-delay="300"
136
+ data-tooltip-append-to-body="true">
137
+ <div class="action-icon igz-icon-download"></div>
138
+ </div>
139
+ </div>
139
140
  <igz-actions-panes data-filters-toggle-method="$ctrl.toggleFilters()"
140
141
  data-show-filter-icon="true"
141
142
  data-filters-counter="$ctrl.activeFilters"