Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
baffc0a4
未验证
提交
baffc0a4
编辑于
8 years ago
作者:
Kamil Trzciński
浏览文件
操作
下载
补丁
差异文件
Add apiCiLongPolling option to use a new reds queueing mechanism
上级
c481d4a9
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
5
隐藏空白变更内容
行内
左右并排
显示
5 个更改的文件
README.md
+2
-0
2 个添加, 0 个删除
README.md
internal/builds/register.go
+94
-0
94 个添加, 0 个删除
internal/builds/register.go
internal/config/config.go
+1
-0
1 个添加, 0 个删除
internal/config/config.go
internal/upstream/routes.go
+4
-2
4 个添加, 2 个删除
internal/upstream/routes.go
main.go
+2
-0
2 个添加, 0 个删除
main.go
有
103 个添加
和
2 个删除
README.md
+
2
−
0
浏览文件 @
baffc0a4
...
...
@@ -36,6 +36,8 @@ gitlab-workhorse'][brief-history-blog].
gitlab-workhorse [OPTIONS]
Options:
-apiCiLongPolling duration
Long polling duration for job requesting for runners (default 0s - disabled)
-apiLimit uint
Number of API requests allowed at single time
-apiQueueDuration duration
...
...
此差异已折叠。
点击以展开。
internal/builds/register.go
0 → 100644
+
94
−
0
浏览文件 @
baffc0a4
package
builds
import
(
"bytes"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/redis"
"io"
"io/ioutil"
"net/http"
"time"
)
const
MaxRegisterBodySize
=
4
*
1024
func
readRunnerQueueKey
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
string
,
error
)
{
limitedBody
:=
http
.
MaxBytesReader
(
w
,
r
.
Body
,
MaxRegisterBodySize
)
defer
limitedBody
.
Close
()
// Read body
var
body
bytes
.
Buffer
_
,
err
:=
io
.
Copy
(
&
body
,
limitedBody
)
if
err
!=
nil
{
return
""
,
err
}
r
.
Body
=
ioutil
.
NopCloser
(
&
body
)
tmpReq
:=
*
r
tmpReq
.
Body
=
ioutil
.
NopCloser
(
bytes
.
NewReader
(
body
.
Bytes
()))
err
=
tmpReq
.
ParseForm
()
if
err
!=
nil
{
return
""
,
err
}
token
:=
tmpReq
.
FormValue
(
"token"
)
if
token
==
""
{
return
""
,
nil
}
key
:=
"runner:build_queue:"
+
token
return
key
,
nil
}
func
RegisterHandler
(
h
http
.
Handler
,
pollingDuration
time
.
Duration
)
http
.
Handler
{
if
pollingDuration
==
0
{
return
h
}
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
lastUpdate
:=
r
.
Header
.
Get
(
"X-GitLab-Last-Update"
)
if
lastUpdate
!=
""
{
// We could have a fail-over implementation here, for old runners, that:
// Proxies the requests, if this is 204, we delay the response to client,
// By checking the response from handler, and reading `X-GitLab-Last-Update`,
// and then watching on a key
h
.
ServeHTTP
(
w
,
r
)
return
}
queueKey
,
err
:=
readRunnerQueueKey
(
w
,
r
)
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
err
)
return
}
result
,
err
:=
redis
.
WatchKey
(
queueKey
,
lastUpdate
,
pollingDuration
)
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
err
)
return
}
switch
result
{
// It means that we detected a change before starting watching on change,
// We proxy request to Rails, to see whether we can receive the build
case
redis
.
WatchKeyStatusAlreadyChanged
:
h
.
ServeHTTP
(
w
,
r
)
// It means that we detected a change after watching.
// We could potentially proxy request to Rails, but...
// We can end-up with unreliable responses,
// as don't really know whether ResponseWriter is still in a sane state,
// whether the connection is not dead
case
redis
.
WatchKeyStatusSeenChange
:
w
.
WriteHeader
(
204
)
// When we receive one of these statuses, it means that we detected no change,
// so we return to runner 204, which means nothing got changed,
// and there's no new builds to process
case
redis
.
WatchKeyStatusTimeout
,
redis
.
WatchKeyStatusNoChange
:
w
.
WriteHeader
(
204
)
}
})
}
此差异已折叠。
点击以展开。
internal/config/config.go
+
1
−
0
浏览文件 @
baffc0a4
...
...
@@ -38,6 +38,7 @@ type Config struct {
APILimit
uint
`toml:"-"`
APIQueueLimit
uint
`toml:"-"`
APIQueueTimeout
time
.
Duration
`toml:"-"`
APICILongPolling
time
.
Duration
`toml:"-"`
}
// LoadConfig from a file
...
...
此差异已折叠。
点击以展开。
internal/upstream/routes.go
+
4
−
2
浏览文件 @
baffc0a4
...
...
@@ -9,6 +9,7 @@ import (
apipkg
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/artifacts"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/builds"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/git"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/lfs"
...
...
@@ -118,6 +119,7 @@ func (u *Upstream) configureRoutes() {
uploadAccelerateProxy
:=
upload
.
Accelerate
(
path
.
Join
(
u
.
DocumentRoot
,
"uploads/tmp"
),
proxy
)
ciAPIProxyQueue
:=
queueing
.
QueueRequests
(
uploadAccelerateProxy
,
u
.
APILimit
,
u
.
APIQueueLimit
,
u
.
APIQueueTimeout
)
ciAPILongPolling
:=
builds
.
RegisterHandler
(
ciAPIProxyQueue
,
u
.
APICILongPolling
)
u
.
Routes
=
[]
routeEntry
{
// Git Clone
...
...
@@ -132,8 +134,8 @@ func (u *Upstream) configureRoutes() {
// Terminal websocket
wsRoute
(
projectPattern
+
`environments/[0-9]+/terminal.ws\z`
,
terminal
.
Handler
(
api
)),
// Limit capacity given to builds/register.json
route
(
""
,
ciAPIPattern
+
`v1/builds/register.json\z`
,
ciAPI
ProxyQueue
),
// L
ong poll and l
imit capacity given to builds/register.json
route
(
""
,
ciAPIPattern
+
`v1/builds/register.json\z`
,
ciAPI
LongPolling
),
// Explicitly proxy API requests
route
(
""
,
apiPattern
,
proxy
),
...
...
此差异已折叠。
点击以展开。
main.go
+
2
−
0
浏览文件 @
baffc0a4
...
...
@@ -51,6 +51,7 @@ var secretPath = flag.String("secretPath", "./.gitlab_workhorse_secret", "File w
var
apiLimit
=
flag
.
Uint
(
"apiLimit"
,
0
,
"Number of API requests allowed at single time"
)
var
apiQueueLimit
=
flag
.
Uint
(
"apiQueueLimit"
,
0
,
"Number of API requests allowed to be queued"
)
var
apiQueueTimeout
=
flag
.
Duration
(
"apiQueueDuration"
,
queueing
.
DefaultTimeout
,
"Maximum queueing duration of requests"
)
var
apiCiLongPolling
=
flag
.
Duration
(
"apiCiLongPolling"
,
0
,
"Long polling duration for job requesting for runners (default 0s - disabled)"
)
var
logFile
=
flag
.
String
(
"logFile"
,
""
,
"Log file to be used"
)
var
prometheusListenAddr
=
flag
.
String
(
"prometheusListenAddr"
,
""
,
"Prometheus listening address, e.g. ':9100'"
)
...
...
@@ -121,6 +122,7 @@ func main() {
APILimit
:
*
apiLimit
,
APIQueueLimit
:
*
apiQueueLimit
,
APIQueueTimeout
:
*
apiQueueTimeout
,
APICILongPolling
:
*
apiCiLongPolling
,
}
if
*
configFile
!=
""
{
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录