-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8177 from hashicorp/f-ui/monitor
UI: Client and Server Monitor
- Loading branch information
Showing
41 changed files
with
1,464 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import AbstractAbility from './abstract'; | ||
import { computed, get } from '@ember/object'; | ||
import { or } from '@ember/object/computed'; | ||
|
||
export default class Client extends AbstractAbility { | ||
@or('bypassAuthorization', 'selfTokenIsManagement', 'policiesIncludeAgentReadOrWrite') | ||
canRead; | ||
|
||
@computed('token.selfTokenPolicies.[]') | ||
get policiesIncludeAgentReadOrWrite() { | ||
const policies = (get(this, 'token.selfTokenPolicies') || []) | ||
.toArray() | ||
.map(policy => get(policy, 'rulesJSON.Agent.Policy')) | ||
.compact(); | ||
|
||
return policies.some(policy => policy === 'read' || policy === 'write'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { inject as service } from '@ember/service'; | ||
import Component from '@ember/component'; | ||
import { computed } from '@ember/object'; | ||
import { assert } from '@ember/debug'; | ||
import { tagName } from '@ember-decorators/component'; | ||
import classic from 'ember-classic-decorator'; | ||
import Log from 'nomad-ui/utils/classes/log'; | ||
|
||
const LEVELS = ['error', 'warn', 'info', 'debug', 'trace']; | ||
|
||
@classic | ||
@tagName('') | ||
export default class AgentMonitor extends Component { | ||
@service token; | ||
|
||
client = null; | ||
server = null; | ||
level = LEVELS[2]; | ||
onLevelChange() {} | ||
|
||
levels = LEVELS; | ||
monitorUrl = '/v1/agent/monitor'; | ||
isStreaming = true; | ||
logger = null; | ||
|
||
@computed('level', 'client.id', 'server.id') | ||
get monitorParams() { | ||
assert( | ||
'Provide a client OR a server to AgentMonitor, not both.', | ||
this.server != null || this.client != null | ||
); | ||
|
||
const type = this.server ? 'server_id' : 'client_id'; | ||
const id = this.server ? this.server.id : this.client && this.client.id; | ||
|
||
return { | ||
log_level: this.level, | ||
[type]: id, | ||
}; | ||
} | ||
|
||
didInsertElement() { | ||
this.updateLogger(); | ||
} | ||
|
||
updateLogger() { | ||
let currentTail = this.logger ? this.logger.tail : ''; | ||
if (currentTail) { | ||
currentTail += `\n...changing log level to ${this.level}...\n\n`; | ||
} | ||
this.set( | ||
'logger', | ||
Log.create({ | ||
logFetch: url => this.token.authorizedRequest(url), | ||
params: this.monitorParams, | ||
url: this.monitorUrl, | ||
tail: currentTail, | ||
}) | ||
); | ||
} | ||
|
||
setLevel(level) { | ||
this.logger.stop(); | ||
this.set('level', level); | ||
this.onLevelChange(level); | ||
this.updateLogger(); | ||
} | ||
|
||
toggleStream() { | ||
this.set('streamMode', 'streaming'); | ||
this.toggleProperty('isStreaming'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Component from '@ember/component'; | ||
import { tagName } from '@ember-decorators/component'; | ||
|
||
@tagName('') | ||
export default class ClientSubnav extends Component {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Component from '@ember/component'; | ||
import { tagName } from '@ember-decorators/component'; | ||
|
||
@tagName('') | ||
export default class ForbiddenMessage extends Component {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Component from '@ember/component'; | ||
import { tagName } from '@ember-decorators/component'; | ||
|
||
@tagName('') | ||
export default class ServerSubnav extends Component {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Controller from '@ember/controller'; | ||
|
||
export default class ClientMonitorController extends Controller { | ||
queryParams = ['level']; | ||
level = 'info'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,5 @@ | ||
import { alias } from '@ember/object/computed'; | ||
import Controller from '@ember/controller'; | ||
import Sortable from 'nomad-ui/mixins/sortable'; | ||
|
||
export default class ServersController extends Controller.extend(Sortable) { | ||
@alias('model.nodes') nodes; | ||
@alias('model.agents') agents; | ||
|
||
queryParams = [ | ||
{ | ||
currentPage: 'page', | ||
}, | ||
{ | ||
sortProperty: 'sort', | ||
}, | ||
{ | ||
sortDescending: 'desc', | ||
}, | ||
]; | ||
|
||
currentPage = 1; | ||
pageSize = 8; | ||
|
||
sortProperty = 'isLeader'; | ||
sortDescending = true; | ||
|
||
export default class ServersController extends Controller { | ||
isForbidden = false; | ||
|
||
@alias('agents') listToSort; | ||
@alias('listSorted') sortedAgents; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
import { alias } from '@ember/object/computed'; | ||
import Controller, { inject as controller } from '@ember/controller'; | ||
import Sortable from 'nomad-ui/mixins/sortable'; | ||
|
||
export default class IndexController extends Controller { | ||
export default class IndexController extends Controller.extend(Sortable) { | ||
@controller('servers') serversController; | ||
@alias('serversController.isForbidden') isForbidden; | ||
|
||
@alias('model.nodes') nodes; | ||
@alias('model.agents') agents; | ||
|
||
queryParams = [ | ||
{ | ||
currentPage: 'page', | ||
}, | ||
{ | ||
sortProperty: 'sort', | ||
}, | ||
{ | ||
sortDescending: 'desc', | ||
}, | ||
]; | ||
|
||
currentPage = 1; | ||
pageSize = 8; | ||
|
||
sortProperty = 'isLeader'; | ||
sortDescending = true; | ||
|
||
@alias('agents') listToSort; | ||
@alias('listSorted') sortedAgents; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Controller from '@ember/controller'; | ||
|
||
export default class ServerMonitorController extends Controller { | ||
queryParams = ['level']; | ||
level = 'info'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.