-
-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): support resource monitor (#1468)
* feat(server): support resource monitor * test(server): add monitor test * fix(server): get app namespace by GetApplicationNamespaceByAppId * chore: change prometheus conf * chore(build): add prometheus * fix: build * chore
- Loading branch information
Showing
20 changed files
with
475 additions
and
10 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
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
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,25 @@ | ||
fullnameOverride: prometheus | ||
alertmanager: | ||
enabled: false | ||
grafana: | ||
enabled: false | ||
coreDns: | ||
enabled: false | ||
nodeExporter: | ||
enabled: false | ||
kubeApiServer: | ||
enabled: false | ||
kubeScheduler: | ||
enabled: false | ||
kubeControllerManager: | ||
enabled: false | ||
kubeEtcd: | ||
enabled: false | ||
kubeProxy: | ||
enabled: false | ||
kubeStateMetrics: | ||
enabled: false | ||
prometheus: | ||
networkPolicy: | ||
enabled: true | ||
ingress: [] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
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 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"semi": false | ||
} |
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,104 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import { api, EnsureTestToken, GetRegion, GetRuntime } from '../api' | ||
import { Config } from '../config' | ||
|
||
describe('query monitor metrics normally', () => { | ||
let appid = Config.TEST_APPID | ||
let token = null | ||
beforeAll(async () => { | ||
token = await EnsureTestToken() | ||
expect(token).toBeTruthy() | ||
}) | ||
|
||
test( | ||
'query monitor metrics', | ||
async () => { | ||
const metrics = [ | ||
'cpuUsage', | ||
'memoryUsage', | ||
'storageUsage', | ||
'databaseUsage', | ||
] | ||
|
||
const query = { | ||
q: metrics, | ||
step: 300, | ||
} | ||
|
||
const res = await api.get(`/v1/monitor/${appid}/metrics`, { | ||
params: query, | ||
headers: { Authorization: `Bearer ${token}` }, | ||
}) | ||
|
||
expect(res.status).toBe(200) | ||
|
||
const data = res.data?.data | ||
expect(Object.keys(data)).toEqual(expect.arrayContaining(metrics)) | ||
|
||
Object.values(data).forEach((v: []) => { | ||
expect(Array.isArray(v)).toBeTruthy() | ||
v.forEach((item) => { | ||
expect([ | ||
['values', 'metric'], | ||
['value', 'metric'], | ||
]).toContainEqual(expect.arrayContaining(Object.keys(item))) | ||
}) | ||
}) | ||
}, | ||
10 * 1000, | ||
) | ||
}) | ||
|
||
describe('query monitor metrics with invalid inputs', () => { | ||
let appid = Config.TEST_APPID | ||
let token = null | ||
beforeAll(async () => { | ||
token = await EnsureTestToken() | ||
expect(token).toBeTruthy() | ||
}) | ||
|
||
test( | ||
'query monitor metrics with invalid step', | ||
async () => { | ||
const metrics = [ | ||
'cpuUsage', | ||
'memoryUsage', | ||
'storageUsage', | ||
'databaseUsage', | ||
] | ||
|
||
const query = { | ||
q: metrics, | ||
step: 50, | ||
} | ||
|
||
const res = await api.get(`/v1/monitor/${appid}/metrics`, { | ||
params: query, | ||
headers: { Authorization: `Bearer ${token}` }, | ||
}) | ||
|
||
expect(res.status).toBe(400) | ||
}, | ||
10 * 1000, | ||
) | ||
|
||
test( | ||
'query monitor metrics with invalid metrics', | ||
async () => { | ||
const metrics = ['cpuUsage', 'memoryUsage', 'storageUsage', 'invalid'] | ||
|
||
const query = { | ||
q: metrics, | ||
step: 50, | ||
} | ||
|
||
const res = await api.get(`/v1/monitor/${appid}/metrics`, { | ||
params: query, | ||
headers: { Authorization: `Bearer ${token}` }, | ||
}) | ||
|
||
expect(res.status).toBe(400) | ||
}, | ||
10 * 1000, | ||
) | ||
}) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
}, | ||
"dependencies": { | ||
"axios": "^1.4.0", | ||
"dotenv": "^16.3.1", | ||
"mongodb": "^5.7.0" | ||
} | ||
} |
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
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
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,22 @@ | ||
import { ApiProperty } from '@nestjs/swagger' | ||
import { IsArray, IsEnum, IsNumber, Max, Min } from 'class-validator' | ||
import { MonitorMetric } from '../monitor.service' | ||
import { Transform } from 'class-transformer' | ||
|
||
export class QueryMetricsDto { | ||
@ApiProperty({ isArray: true, enum: MonitorMetric }) | ||
@IsEnum(MonitorMetric, { each: true }) | ||
@IsArray() | ||
q: MonitorMetric[] | ||
|
||
@ApiProperty({ | ||
minimum: 60, | ||
maximum: 3600, | ||
description: 'Query step in seconds', | ||
}) | ||
@IsNumber() | ||
@Min(60) | ||
@Max(3600) | ||
@Transform(({ value }) => Number(value)) | ||
step: number | ||
} |
Oops, something went wrong.