Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gzupanda
code-server
提交
75c8fdee
C
code-server
项目概览
gzupanda
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
75c8fdee
编写于
8月 31, 2020
作者:
J
Jacob Goldman
提交者:
GitHub
8月 31, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added /healthz JSON response for heartbeat data. #1940 (#1984)
上级
de41646f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
7 deletion
+46
-7
src/node/app/health.ts
src/node/app/health.ts
+32
-0
src/node/entry.ts
src/node/entry.ts
+3
-1
src/node/http.ts
src/node/http.ts
+11
-6
未找到文件。
src/node/app/health.ts
0 → 100644
浏览文件 @
75c8fdee
import
*
as
http
from
"
http
"
import
{
HttpCode
,
HttpError
}
from
"
../../common/http
"
import
{
HttpProvider
,
HttpResponse
,
Route
,
Heart
,
HttpProviderOptions
}
from
"
../http
"
/**
* Check the heartbeat.
*/
export
class
HealthHttpProvider
extends
HttpProvider
{
public
constructor
(
options
:
HttpProviderOptions
,
private
readonly
heart
:
Heart
)
{
super
(
options
)
}
public
async
handleRequest
(
route
:
Route
,
request
:
http
.
IncomingMessage
):
Promise
<
HttpResponse
>
{
if
(
!
this
.
authenticated
(
request
))
{
if
(
this
.
isRoot
(
route
))
{
return
{
redirect
:
"
/login
"
,
query
:
{
to
:
route
.
fullPath
}
}
}
throw
new
HttpError
(
"
Unauthorized
"
,
HttpCode
.
Unauthorized
)
}
const
result
=
{
cache
:
false
,
mime
:
"
application/json
"
,
content
:
{
status
:
this
.
heart
.
alive
()
?
"
alive
"
:
"
expired
"
,
lastHeartbeat
:
this
.
heart
.
lastHeartbeat
,
},
}
return
result
}
}
src/node/entry.ts
浏览文件 @
75c8fdee
...
...
@@ -3,8 +3,9 @@ import * as cp from "child_process"
import
{
promises
as
fs
}
from
"
fs
"
import
http
from
"
http
"
import
*
as
path
from
"
path
"
import
{
CliMessage
,
OpenCommandPipeArgs
}
from
"
../../lib/vscode/src/vs/server/ipc
"
import
{
CliMessage
}
from
"
../../lib/vscode/src/vs/server/ipc
"
import
{
plural
}
from
"
../common/util
"
import
{
HealthHttpProvider
}
from
"
./app/health
"
import
{
LoginHttpProvider
}
from
"
./app/login
"
import
{
ProxyHttpProvider
}
from
"
./app/proxy
"
import
{
StaticHttpProvider
}
from
"
./app/static
"
...
...
@@ -80,6 +81,7 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void>
httpServer
.
registerHttpProvider
(
"
/proxy
"
,
ProxyHttpProvider
)
httpServer
.
registerHttpProvider
(
"
/login
"
,
LoginHttpProvider
,
args
.
config
!
,
envPassword
)
httpServer
.
registerHttpProvider
(
"
/static
"
,
StaticHttpProvider
)
httpServer
.
registerHttpProvider
(
"
/healthz
"
,
HealthHttpProvider
,
httpServer
.
heart
)
await
loadPlugins
(
httpServer
,
args
)
...
...
src/node/http.ts
浏览文件 @
75c8fdee
...
...
@@ -396,23 +396,26 @@ export abstract class HttpProvider {
export
class
Heart
{
private
heartbeatTimer
?:
NodeJS
.
Timeout
private
heartbeatInterval
=
60000
p
rivate
lastHeartbeat
=
0
p
ublic
lastHeartbeat
=
0
public
constructor
(
private
readonly
heartbeatPath
:
string
,
private
readonly
isActive
:
()
=>
Promise
<
boolean
>
)
{}
public
alive
():
boolean
{
const
now
=
Date
.
now
()
return
now
-
this
.
lastHeartbeat
<
this
.
heartbeatInterval
}
/**
* Write to the heartbeat file if we haven't already done so within the
* timeout and start or reset a timer that keeps running as long as there is
* activity. Failures are logged as warnings.
*/
public
beat
():
void
{
const
now
=
Date
.
now
()
if
(
now
-
this
.
lastHeartbeat
>=
this
.
heartbeatInterval
)
{
if
(
!
this
.
alive
())
{
logger
.
trace
(
"
heartbeat
"
)
fs
.
outputFile
(
this
.
heartbeatPath
,
""
).
catch
((
error
)
=>
{
logger
.
warn
(
error
.
message
)
})
this
.
lastHeartbeat
=
now
this
.
lastHeartbeat
=
Date
.
now
()
if
(
typeof
this
.
heartbeatTimer
!==
"
undefined
"
)
{
clearTimeout
(
this
.
heartbeatTimer
)
}
...
...
@@ -457,7 +460,7 @@ export class HttpServer {
private
listenPromise
:
Promise
<
string
|
null
>
|
undefined
public
readonly
protocol
:
"
http
"
|
"
https
"
private
readonly
providers
=
new
Map
<
string
,
HttpProvider
>
()
p
rivate
readonly
heart
:
Heart
p
ublic
readonly
heart
:
Heart
private
readonly
socketProvider
=
new
SocketProxyProvider
()
/**
...
...
@@ -602,8 +605,10 @@ export class HttpServer {
}
private
onRequest
=
async
(
request
:
http
.
IncomingMessage
,
response
:
http
.
ServerResponse
):
Promise
<
void
>
=>
{
this
.
heart
.
beat
()
const
route
=
this
.
parseUrl
(
request
)
if
(
route
.
providerBase
!==
"
/healthz
"
)
{
this
.
heart
.
beat
()
}
const
write
=
(
payload
:
HttpResponse
):
void
=>
{
response
.
writeHead
(
payload
.
redirect
?
HttpCode
.
Redirect
:
payload
.
code
||
HttpCode
.
Ok
,
{
"
Content-Type
"
:
payload
.
mime
||
getMediaMime
(
payload
.
filePath
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录