mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
pkg metrics
This commit is contained in:
committed by
Aiden McClelland
parent
20cdb47cb0
commit
fc506c387f
@@ -109,6 +109,9 @@ export module RR {
|
||||
export type GetPackageLogsReq = { id: string, before?: string } // package.logs
|
||||
export type GetPackageLogsRes = Log[]
|
||||
|
||||
export type GetPackageMetricsReq = { id: string } // package.metrics
|
||||
export type GetPackageMetricsRes = Metric
|
||||
|
||||
export type InstallPackageReq = WithExpire<{ id: string, version: string }> // package.install
|
||||
export type InstallPackageRes = WithRevision<null>
|
||||
|
||||
@@ -231,6 +234,13 @@ export interface Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
export interface Metric {
|
||||
[key: string]: {
|
||||
value: string | number | null
|
||||
unit?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface DiskInfo {
|
||||
[id: string]: DiskInfoEntry
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
|
||||
|
||||
abstract getServerMetrics (params: RR.GetServerMetricsReq): Promise<RR.GetServerMetricsRes>
|
||||
|
||||
abstract getPkgMetrics (params: RR.GetPackageMetricsReq): Promise<RR.GetPackageMetricsRes>
|
||||
|
||||
protected abstract updateServerRaw (params: RR.UpdateServerReq): Promise<RR.UpdateServerRes>
|
||||
updateServer = (params: RR.UpdateServerReq) => this.syncResponse(
|
||||
() => this.updateServerRaw(params),
|
||||
|
||||
@@ -141,6 +141,10 @@ export class LiveApiService extends ApiService {
|
||||
return this.http.rpcRequest( { method: 'package.logs', params })
|
||||
}
|
||||
|
||||
async getPkgMetrics (params: RR.GetPackageMetricsReq): Promise<RR.GetPackageMetricsRes> {
|
||||
return this.http.rpcRequest({ method: 'package.metrics', params })
|
||||
}
|
||||
|
||||
async installPackageRaw (params: RR.InstallPackageReq): Promise<RR.InstallPackageRes> {
|
||||
return this.http.rpcRequest({ method: 'package.install', params })
|
||||
}
|
||||
|
||||
@@ -1,23 +1,35 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { pauseFor } from '../../util/misc.util'
|
||||
import { ApiService } from './api.service'
|
||||
import { PatchOp } from 'patch-db-client'
|
||||
import { PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/services/patch-db/data-model'
|
||||
import { RR, WithRevision } from './api-types'
|
||||
import { Observable } from 'rxjs'
|
||||
import { PatchOp, Store, Update } from 'patch-db-client'
|
||||
import { DataModel, PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/services/patch-db/data-model'
|
||||
import { RR } from './api-types'
|
||||
import { parsePropertiesPermissive } from 'src/app/util/properties.util'
|
||||
import { Mock } from './mock-app-fixures'
|
||||
import { HttpService } from '../http.service'
|
||||
import markdown from 'raw-loader!src/assets/markdown/md-sample.md'
|
||||
import { revision } from '@start9labs/emver'
|
||||
|
||||
@Injectable()
|
||||
export class MockApiService extends ApiService {
|
||||
sequence = 0
|
||||
welcomeAck = false
|
||||
|
||||
constructor (
|
||||
private readonly http: HttpService,
|
||||
) { super() }
|
||||
|
||||
// every time a patch is returned from the mock, we override its sequence to be 1 more than the last sequence in the patch-db as provided by `o`.
|
||||
watch$ (store: Store<DataModel>): Observable<Update<DataModel>> {
|
||||
store.sequence$.subscribe(seq => {
|
||||
console.log('INCOMING: ', seq)
|
||||
if (this.sequence < seq) {
|
||||
this.sequence = seq
|
||||
}
|
||||
})
|
||||
return super.watch$()
|
||||
}
|
||||
|
||||
async getStatic (url: string): Promise<string> {
|
||||
await pauseFor(2000)
|
||||
return markdown
|
||||
@@ -86,16 +98,27 @@ export class MockApiService extends ApiService {
|
||||
return Mock.getServerMetrics()
|
||||
}
|
||||
|
||||
async getPkgMetrics (params: RR.GetServerMetricsReq): Promise<RR.GetPackageMetricsRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.getAppMetrics()
|
||||
}
|
||||
|
||||
async updateServerRaw (params: RR.UpdateServerReq): Promise<RR.UpdateServerRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/status',
|
||||
value: ServerStatus.Updating,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/status',
|
||||
value: ServerStatus.Updating,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
async restartServer (params: RR.RestartServerReq): Promise<RR.RestartServerRes> {
|
||||
@@ -119,31 +142,39 @@ export class MockApiService extends ApiService {
|
||||
|
||||
async setRegistryRaw (params: RR.SetRegistryReq): Promise<RR.SetRegistryRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/registry',
|
||||
value: params.url,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/registry',
|
||||
value: params.url,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
// notification
|
||||
|
||||
async getNotificationsRaw (params: RR.GetNotificationsReq): Promise<RR.GetNotificationsRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/unread-notification-count',
|
||||
value: 0,
|
||||
},
|
||||
]
|
||||
const { revision } = await this.http.rpcRequest({ method: 'db.patch', params: { patch } }) as WithRevision<null>
|
||||
return {
|
||||
response: Mock.Notifications,
|
||||
revision,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/unread-notification-count',
|
||||
value: 0,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,36 +192,48 @@ export class MockApiService extends ApiService {
|
||||
|
||||
async connectWifiRaw (params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/wifi/selected',
|
||||
value: params.ssid,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/wifi/selected',
|
||||
value: params.ssid,
|
||||
},
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/wifi/connected',
|
||||
value: params.ssid,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/wifi/connected',
|
||||
value: params.ssid,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
async deleteWifiRaw (params: RR.DeleteWifiReq): Promise<RR.DeleteWifiRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/wifi/selected',
|
||||
value: null,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/wifi/selected',
|
||||
value: null,
|
||||
},
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/wifi/connected',
|
||||
value: null,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/wifi/connected',
|
||||
value: null,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
// ssh
|
||||
@@ -214,14 +257,20 @@ export class MockApiService extends ApiService {
|
||||
|
||||
async createBackupRaw (params: RR.CreateBackupReq): Promise<RR.CreateBackupRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/status',
|
||||
value: ServerStatus.BackingUp,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/status',
|
||||
value: ServerStatus.BackingUp,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
async restoreBackupRaw (params: RR.RestoreBackupReq): Promise<RR.RestoreBackupRes> {
|
||||
@@ -270,14 +319,20 @@ export class MockApiService extends ApiService {
|
||||
'read-complete': false,
|
||||
},
|
||||
}
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.ADD,
|
||||
path: `/package-data/${params.id}`,
|
||||
value: pkg,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.ADD,
|
||||
path: `/package-data/${params.id}`,
|
||||
value: pkg,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
async dryUpdatePackage (params: RR.DryUpdatePackageReq): Promise<RR.DryUpdatePackageRes> {
|
||||
@@ -297,31 +352,43 @@ export class MockApiService extends ApiService {
|
||||
|
||||
async setPackageConfigRaw (params: RR.SetPackageConfigReq): Promise<RR.SetPackageConfigRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/configured`,
|
||||
value: true,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/configured`,
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/main/status`,
|
||||
value: PackageMainStatus.Running,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/main/status`,
|
||||
value: PackageMainStatus.Running,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
async restorePackageRaw (params: RR.RestorePackageReq): Promise<RR.RestorePackageRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/main/status`,
|
||||
value: PackageMainStatus.Restoring,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/main/status`,
|
||||
value: PackageMainStatus.Restoring,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
async executePackageAction (params: RR.ExecutePackageActionReq): Promise<RR.ExecutePackageActionRes> {
|
||||
@@ -336,14 +403,20 @@ export class MockApiService extends ApiService {
|
||||
|
||||
async startPackageRaw (params: RR.StartPackageReq): Promise<RR.StartPackageRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/main/status`,
|
||||
value: PackageMainStatus.Running,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/main/status`,
|
||||
value: PackageMainStatus.Running,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
async dryStopPackage (params: RR.DryStopPackageReq): Promise<RR.DryStopPackageRes> {
|
||||
@@ -353,26 +426,20 @@ export class MockApiService extends ApiService {
|
||||
|
||||
async stopPackageRaw (params: RR.StopPackageReq): Promise<RR.StopPackageRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/main/status`,
|
||||
value: PackageMainStatus.Stopping,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/main/status`,
|
||||
value: PackageMainStatus.Stopping,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
]
|
||||
const res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
|
||||
setTimeout(() => {
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/installed/status/main/status`,
|
||||
value: PackageMainStatus.Stopped,
|
||||
},
|
||||
]
|
||||
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
|
||||
}, 2000)
|
||||
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
async dryRemovePackage (params: RR.DryRemovePackageReq): Promise<RR.DryRemovePackageRes> {
|
||||
@@ -382,14 +449,20 @@ export class MockApiService extends ApiService {
|
||||
|
||||
async removePackageRaw (params: RR.RemovePackageReq): Promise<RR.RemovePackageRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/state`,
|
||||
value: PackageState.Removing,
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${params.id}/state`,
|
||||
value: PackageState.Removing,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
async dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise<RR.DryConfigureDependencyRes> {
|
||||
@@ -420,4 +493,10 @@ export class MockApiService extends ApiService {
|
||||
await pauseFor(2000)
|
||||
return Mock.AvailableShow[params.id][params.version || 'latest']
|
||||
}
|
||||
|
||||
private nextSequence () {
|
||||
console.log('next')
|
||||
this.sequence++
|
||||
return this.sequence
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DependencyErrorType, DockerIoFormat, Manifest, PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/services/patch-db/data-model'
|
||||
import { NotificationLevel, RR, ServerNotification, ServerNotifications } from './api-types'
|
||||
import { Metric, NotificationLevel, RR, ServerNotification, ServerNotifications } from './api-types'
|
||||
|
||||
export module Mock {
|
||||
|
||||
@@ -888,6 +888,25 @@ export module Mock {
|
||||
}
|
||||
}
|
||||
|
||||
export function getAppMetrics () {
|
||||
const metr: Metric = {
|
||||
'Metric1': {
|
||||
value: Math.random(),
|
||||
unit: 'mi/b',
|
||||
},
|
||||
'Metric2': {
|
||||
value: Math.random(),
|
||||
unit: '%',
|
||||
},
|
||||
'Metric3': {
|
||||
value: 10.1,
|
||||
unit: '%',
|
||||
},
|
||||
}
|
||||
|
||||
return metr
|
||||
}
|
||||
|
||||
export const ServerLogs: RR.GetServerLogsRes = [
|
||||
{
|
||||
timestamp: '2019-12-26T14:20:30.872Z',
|
||||
|
||||
Reference in New Issue
Block a user