Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qa-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
qa-api
Commits
a2d7eee6
Commit
a2d7eee6
authored
Mar 03, 2020
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构镜像仓库接口 qa-test
parent
e87e88ae
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
202 additions
and
8 deletions
+202
-8
env.js
app/controller/env.js
+1
-1
repoNew.js
app/controller/repoNew.js
+105
-0
resource.js
app/controller/resource.js
+4
-2
index.js
app/index.js
+2
-0
cpuRate.js
app/jobs/cpuRate.js
+4
-2
memoryRate.js
app/jobs/memoryRate.js
+1
-1
ProConfig.js
app/model/mongo/qa_api/ProConfig.js
+2
-1
repoServiceNew.js
app/service/repoServiceNew.js
+81
-0
app.config.js
src/app.config.js
+2
-1
No files found.
app/controller/env.js
View file @
a2d7eee6
...
...
@@ -73,7 +73,7 @@ const create = async (ctx) => {
type
:
app
.
type
,
serviceName
:
app
.
appname
,
namespace
:
body
.
namespace
,
image
:
app
.
tag
,
image
:
app
.
tag
.
replace
(
`qa-
${
app
.
type
}
`
,
'
qa-test
'
)
,
label
:
app
.
label
,
domain
:
app
.
domain
,
debug
:
'
"0"
'
,
...
...
app/controller/repoNew.js
0 → 100644
View file @
a2d7eee6
const
Router
=
require
(
'
koa-router
'
)
const
logger
=
require
(
'
koa-log4
'
).
getLogger
()
const
bodyParser
=
require
(
'
koa-bodyparser
'
)
const
ProConfig
=
require
(
'
../service/mongoService
'
).
ProConfig
const
repoServiceNew
=
require
(
'
../service/repoServiceNew
'
)
const
router
=
new
Router
()
module
.
exports
=
router
const
QA
=
'
qa-
'
const
BASETYPE
=
'
base
'
const
QABASE
=
'
qa-base
'
const
QATEST
=
'
qa-test
'
const
formatData
=
(
obj
)
=>
{
const
data
=
[]
// eslint-disable-next-line guard-for-in
for
(
const
i
in
obj
)
{
data
.
push
({
type
:
i
,
repos
:
obj
[
i
],
})
}
data
.
sort
((
a
,
b
)
=>
(
a
.
type
>
b
.
type
?
1
:
-
1
))
return
data
}
const
getAllRepos
=
async
(
ctx
)
=>
{
const
ns
=
[{
namespace
:
QATEST
},
{
namespace
:
QABASE
}]
ctx
.
_domains
=
await
ProConfig
.
getActiveProjectsHostName
()
const
task
=
[]
for
(
let
i
=
0
;
i
<
ns
.
length
;
i
+=
1
)
{
logger
.
info
(
'
要查询的namespace:
'
,
ns
[
i
])
ns
[
i
].
type
=
ns
[
i
].
namespace
.
replace
(
QA
,
''
)
task
.
push
(
repoServiceNew
.
getRepoOfNs
(
ctx
,
ns
[
i
]))
}
await
Promise
.
all
(
task
)
const
obj
=
{}
for
(
const
n
of
ns
)
{
if
(
n
.
type
===
BASETYPE
)
{
obj
[
n
.
type
]
=
n
.
repos
}
else
{
for
(
const
repo
of
n
.
repos
)
{
if
(
!
obj
[
repo
.
type
])
obj
[
repo
.
type
]
=
[]
obj
[
repo
.
type
].
push
(
repo
)
}
}
}
const
data
=
formatData
(
obj
)
ctx
.
body
=
ctx
.
ok
(
data
)
}
const
getBaseRepos
=
async
(
ctx
)
=>
{
const
ns
=
{
type
:
BASETYPE
,
namespace
:
QABASE
,
}
await
repoServiceNew
.
getRepoOfNs
(
ctx
,
ns
)
ctx
.
body
=
ctx
.
ok
([
ns
])
}
const
getAppRepos
=
async
(
ctx
)
=>
{
const
ns
=
{
namespace
:
QATEST
}
ctx
.
_domains
=
await
ProConfig
.
getActiveProjectsHostName
()
await
repoServiceNew
.
getRepoOfNs
(
ctx
,
ns
)
const
obj
=
{}
for
(
const
repo
of
ns
.
repos
)
{
if
(
!
obj
[
repo
.
type
])
obj
[
repo
.
type
]
=
[]
obj
[
repo
.
type
].
push
(
repo
)
}
const
data
=
formatData
(
obj
)
ctx
.
body
=
ctx
.
ok
(
data
)
}
const
getSingleTypeApp
=
async
(
ctx
)
=>
{
let
data
=
[]
const
ns
=
{
namespace
:
ctx
.
request
.
body
.
namespace
}
ctx
.
_domains
=
await
ProConfig
.
getActiveProjectsHostName
()
await
repoServiceNew
.
getRepoOfNs
(
ctx
,
ns
)
for
(
const
repo
of
ns
.
repos
)
{
if
(
repo
.
label
===
ctx
.
request
.
body
.
type
)
{
data
.
push
(
repo
)
}
}
// qa-base 需要去重
if
(
ctx
.
request
.
body
.
type
===
'
base
'
)
{
const
obj
=
{}
data
=
data
.
reduce
((
a
,
b
)
=>
{
obj
[
b
.
type
]
?
''
:
obj
[
b
.
type
]
=
true
&&
a
.
push
(
b
)
return
a
},
[])
}
ctx
.
body
=
ctx
.
ok
(
data
)
}
router
.
use
(
bodyParser
())
.
get
(
'
/getAll
'
,
getAllRepos
)
.
get
(
'
/getBase
'
,
getBaseRepos
)
.
get
(
'
/getApp
'
,
getAppRepos
)
.
post
(
'
/getSingleTypeApp
'
,
getSingleTypeApp
)
app/controller/resource.js
View file @
a2d7eee6
...
...
@@ -43,7 +43,8 @@ const getCpu = async (ctx) => {
const
getCpuInfo
=
async
(
ctx
)
=>
{
const
query
=
handleQuery
(
ctx
.
request
.
query
)
const
list
=
await
CpuResource
.
getCpu2
(
query
,
{
_id
:
0
},
{
Percentage
:
1
})
let
list
=
await
CpuResource
.
getCpu2
(
query
,
{
_id
:
0
},
{
Percentage
:
1
})
list
=
list
.
filter
(
i
=>
i
.
name
.
split
(
'
-
'
).
length
-
2
===
ctx
.
request
.
query
.
name
.
split
(
'
-
'
).
length
)
ctx
.
body
=
ctx
.
ok
(
list
)
}
...
...
@@ -56,7 +57,8 @@ const getMemory = async (ctx) => {
const
getMemoryInfo
=
async
(
ctx
)
=>
{
const
query
=
handleQuery
(
ctx
.
request
.
query
)
const
list
=
await
MemoryResource
.
getMemory2
(
query
,
{
_id
:
0
},
{
Percentage
:
1
})
let
list
=
await
MemoryResource
.
getMemory2
(
query
,
{
_id
:
0
},
{
Percentage
:
1
})
list
=
list
.
filter
(
i
=>
i
.
name
.
split
(
'
-
'
).
length
-
2
===
ctx
.
request
.
query
.
name
.
split
(
'
-
'
).
length
)
ctx
.
body
=
ctx
.
ok
(
list
)
}
...
...
app/index.js
View file @
a2d7eee6
...
...
@@ -23,6 +23,7 @@ const binlog2sql = require('./controller/binlog2sql')
const
harborHook
=
require
(
'
./controller/harborHook
'
)
const
log
=
require
(
'
./controller/log
'
)
const
repo
=
require
(
'
./controller/repo
'
)
const
repoNew
=
require
(
'
./controller/repoNew
'
)
const
envTemplate
=
require
(
'
./controller/envTemplate
'
)
const
env
=
require
(
'
./controller/env
'
)
const
pipeline
=
require
(
'
./controller/pipeline
'
)
...
...
@@ -51,6 +52,7 @@ router
.
use
(
'
/harborHook
'
,
harborHook
.
routes
())
.
use
(
'
/log
'
,
log
.
routes
())
.
use
(
'
/repo
'
,
repo
.
routes
())
.
use
(
'
/repoNew
'
,
repoNew
.
routes
())
.
use
(
'
/envTemplate
'
,
envTemplate
.
routes
())
.
use
(
'
/env
'
,
env
.
routes
())
.
use
(
'
/pipeline
'
,
pipeline
.
routes
())
...
...
app/jobs/cpuRate.js
View file @
a2d7eee6
...
...
@@ -16,6 +16,7 @@ async function job() {
{namespace!~%22kube-system|monitor|rc-test%22}/(100*1000))%20by%20(pod_name)`
,
method
:
'
GET
'
,
})
logger
.
info
(
'
container_spec_cpu_quota
'
,
cpuLimitRes
.
status
,
cpuLimitRes
.
data
.
result
.
length
)
cpuLimitRes
.
data
.
result
.
forEach
((
item
)
=>
{
if
(
item
.
metric
.
pod_name
)
{
...
...
@@ -27,9 +28,10 @@ async function job() {
const
cpuUsageRes
=
await
awaitRequest
({
url
:
`
${
config
.
prometheus
}
/api/v1/query_range?query=sum (rate (container_cpu_usage_seconds_total
{image!="",name=~"^k8s_.*",io_kubernetes_container_name!="POD",pod_name=~"^()()().*$"}[1m])) by
(pod_name)&start=
${
startTime
}
&end=
${
endTime
}
&step=
9
0`
,
(pod_name)&start=
${
startTime
}
&end=
${
endTime
}
&step=
6
0`
,
method
:
'
GET
'
,
})
logger
.
info
(
'
container_cpu_usage_seconds_total
'
,
cpuUsageRes
.
status
,
cpuUsageRes
.
data
.
result
.
length
)
cpuUsageRes
.
data
.
result
.
forEach
((
item
)
=>
{
if
(
item
.
metric
.
pod_name
)
{
...
...
@@ -48,7 +50,7 @@ async function job() {
name
:
item
,
cpuLimit
:
finalCpuLimit
[
item
],
cpuMaxUsage
:
finalCpuUsage
[
item
],
Percentage
:
`
${(
finalCpuUsage
[
item
]
/
finalCpuLimit
[
item
]).
toFixed
(
3
)}
`
,
Percentage
:
`
${(
finalCpuUsage
[
item
]
/
finalCpuLimit
[
item
]).
toFixed
(
4
)}
`
,
}
CpuResource
.
saveCpu
(
data
)
})
...
...
app/jobs/memoryRate.js
View file @
a2d7eee6
...
...
@@ -37,7 +37,7 @@ async function job() {
name
:
item
,
memoryLimit
:
Math
.
round
(
finalMemoryLimit
[
item
]),
memoryMaxUsage
:
Math
.
round
(
finalMemoryUsage
[
item
]),
Percentage
:
`
${(
finalMemoryUsage
[
item
]
/
finalMemoryLimit
[
item
]).
toFixed
(
3
)}
`
,
Percentage
:
`
${(
finalMemoryUsage
[
item
]
/
finalMemoryLimit
[
item
]).
toFixed
(
4
)}
`
,
}
MemoryResource
.
saveMemory
(
data
)
})
...
...
app/model/mongo/qa_api/ProConfig.js
View file @
a2d7eee6
...
...
@@ -42,7 +42,7 @@ const schema = new Schema({
})
schema
.
statics
.
getActiveProjectsHostName
=
function
()
{
return
this
.
find
({
des
:
{
$ne
:
'
海外
'
},
is_active
:
1
}).
select
([
'
host_name
'
,
'
project_name
'
]).
lean
().
then
((
res
)
=>
{
return
this
.
find
({
des
:
{
$ne
:
'
海外
'
},
is_active
:
1
}).
select
([
'
host_name
'
,
'
project_name
'
,
'
type
'
]).
lean
().
then
((
res
)
=>
{
const
reg
=
/^
([\w
-
\.]
+
)\.[\w
-
]
+
\.[
a-z
]
+$/
// 转为对象形式
const
o
=
res
.
reduce
((
prev
,
next
)
=>
{
...
...
@@ -50,6 +50,7 @@ schema.statics.getActiveProjectsHostName = function () {
prev
[
next
.
project_name
]
=
{
hostname
:
next
.
host_name
,
domain
:
regRes
?
regRes
[
1
]
:
''
,
type
:
next
.
type
,
}
return
prev
},
{})
...
...
app/service/repoServiceNew.js
0 → 100644
View file @
a2d7eee6
const
_
=
require
(
'
lodash
'
)
const
config
=
require
(
global
.
configPath
)
const
QA
=
'
qa-
'
const
BASEREPO
=
'
qa-base
'
const
LASTEST
=
'
latest
'
async
function
getTagOfRepo
(
ctx
,
repo
)
{
const
res
=
await
ctx
.
curl
({
uri
:
`
${
config
.
api
.
tke_api
}
/repository/getTags`
,
method
:
'
POST
'
,
body
:
{
reponame
:
repo
.
reponame
,
},
})
repo
.
tags
=
_
.
get
(
res
,
'
body.data.tagInfo
'
,
[]).
map
(
item
=>
item
.
tagName
)
}
async
function
getRepoOfNs
(
ctx
,
ns
)
{
const
isBaseRepo
=
BASEREPO
===
ns
.
namespace
// 服务部署后,在运行中环境,通过label信息来展示列表
const
label
=
ns
.
namespace
.
replace
(
QA
,
''
)
const
res
=
await
ctx
.
curl
({
uri
:
`
${
config
.
api
.
tke_api
}
/repository`
,
method
:
'
POST
'
,
body
:
{
namespace
:
ns
.
namespace
,
},
})
let
repos
=
_
.
get
(
res
,
'
body.data.repoInfo
'
,
[]).
map
((
item
)
=>
{
const
appname
=
item
.
reponame
.
split
(
'
/
'
)[
1
]
const
o
=
{
reponame
:
item
.
reponame
,
appname
,
}
if
(
item
.
reponame
.
indexOf
(
BASEREPO
)
===
-
1
)
{
o
.
hostname
=
(
ctx
.
_domains
[
appname
]
&&
ctx
.
_domains
[
appname
].
hostname
)
||
''
o
.
domain
=
(
ctx
.
_domains
[
appname
]
&&
ctx
.
_domains
[
appname
].
domain
)
||
''
}
return
o
})
const
task
=
[]
for
(
let
i
=
0
,
len
=
repos
.
length
;
i
<
len
;
i
+=
1
)
{
if
(
isBaseRepo
)
{
task
.
push
(
getTagOfRepo
(
ctx
,
repos
[
i
]))
}
}
await
Promise
.
all
(
task
)
// 把tag信息拉平到appname上
const
m
=
[]
repos
.
forEach
((
item
)
=>
{
const
tags
=
item
.
tags
||
[
LASTEST
]
tags
.
forEach
((
tag
)
=>
{
// console.log(1, item, ctx._domains[item.appname])
m
.
push
({
// 部署时用于选择服务模板
type
:
isBaseRepo
?
item
.
appname
:
ctx
.
_domains
[
item
.
appname
].
type
,
label
:
isBaseRepo
?
label
:
ctx
.
_domains
[
item
.
appname
].
type
,
appname
:
isBaseRepo
?
`
${
item
.
appname
}
:
${
tag
}
`
:
item
.
appname
,
tag
:
`
${
item
.
reponame
}
:
${
tag
}
`
,
// domain用于部署服务时的域名映射
domain
:
isBaseRepo
?
`
${
item
.
appname
}${
tag
}
`
:
item
.
domain
,
})
})
})
repos
=
m
repos
.
sort
((
a
,
b
)
=>
(
a
.
appname
>
b
.
appname
?
1
:
-
1
))
ns
.
repos
=
repos
delete
ns
.
repoCount
delete
ns
.
creationTime
delete
ns
.
namespace
}
exports
.
getRepoOfNs
=
getRepoOfNs
src/app.config.js
View file @
a2d7eee6
...
...
@@ -56,5 +56,6 @@ module.exports = {
+
'
=fae6b46742f9f261997a7f4f07bb6ba21f274dc3e602065fff5c4f76cf1dbf53
'
,
sonarHost
:
'
http://sonar.quantgroups.com
'
,
qahomeHost
:
'
http://qa2.liangkebang.com
'
,
snorDingRobotAddr
:
'
https://oapi.dingtalk.com/robot/send?access_token=0da7a1066b42bb23f079dacec3b7975e8cc12cee7efc5316a9b5b1900779a407
'
,
snorDingRobotAddr
:
'
https://oapi.dingtalk.com/robot/send?access_token
'
+
'
=0da7a1066b42bb23f079dacec3b7975e8cc12cee7efc5316a9b5b1900779a407
'
,
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment