فهرست منبع

Merge pull request #501 from smiclea/diagnostics

Add ability to download diagnostics JSON file
Ionut BALUTOIU 6 سال پیش
والد
کامیت
b1293821c9
3فایلهای تغییر یافته به همراه25 افزوده شده و 1 حذف شده
  1. 8 0
      src/components/pages/LogsPage/DownloadsContent.jsx
  2. 5 0
      src/components/pages/LogsPage/LogsPage.jsx
  3. 12 1
      src/stores/LogStore.js

+ 8 - 0
src/components/pages/LogsPage/DownloadsContent.jsx

@@ -149,6 +149,14 @@ class DownloadsContent extends React.Component<Props, State> {
   renderLogs() {
     return (
       <Logs>
+        <Log>
+          <LogDownload
+            onClick={() => {
+              this.props.onDownloadClick('__diagnostics__')
+            }}
+          />
+          <LogName>diagnostics</LogName>
+        </Log>
         {this.props.logs.map(log => (
           <Log key={log.log_name}>
             <LogDownload

+ 5 - 0
src/components/pages/LogsPage/LogsPage.jsx

@@ -124,6 +124,11 @@ class LogsPage extends React.Component<{}, State> {
   }
 
   handleDownloadClick(logName: string, startDate: ?Date, endDate: ?Date) {
+    if (logName === '__diagnostics__') {
+      logStore.downloadDiagnostics()
+      return
+    }
+
     if (startDate && endDate && endDate.getTime() < startDate.getTime()) {
       notificationStore.alert('End time must be greater than start time', 'error')
       return

+ 12 - 1
src/stores/LogStore.js

@@ -19,9 +19,10 @@ import cookie from 'js-cookie'
 
 import type { Log } from '../types/Log'
 
-import { coriolisUrl } from '../constants'
+import { coriolisUrl, servicesUrl } from '../constants'
 
 import notificationStore from '../stores/NotificationStore'
+import userStore from '../stores/UserStore'
 
 import apiCaller from '../utils/ApiCaller'
 import DateUtils from '../utils/DateUtils'
@@ -65,6 +66,16 @@ class LogStore {
     DomUtils.executeDownloadLink(url)
   }
 
+  async downloadDiagnostics() {
+    let loggedUser = userStore.loggedUser
+    if (!loggedUser) {
+      throw new Error('No logged user!')
+    }
+    let projectId = loggedUser.project.id
+    let response = await apiCaller.send({ url: `${servicesUrl.coriolis}/${projectId}/diagnostics` })
+    DomUtils.download(JSON.stringify(response.data), 'diagnostics.json')
+  }
+
   socket: WebSocket
   startLiveFeed(options: { logName: string, severityLevel: number }) {
     let { logName, severityLevel } = options