simpleservice
1.0.0
一個簡單且可配置的服務,例如,可以用於測試容器編排設置(包括健康檢查端點)。
請注意, simpleservice
的版本(例如0.4.0
)在以下內容中使用,請參閱所創建的相應Docker圖像中使用的標籤。此GitHub存儲庫中沒有標籤或版本。
內容:
除了此處列出的端點外,還請參見下面的“運行時行為”部分。
/env
[0.5.0+]原則回應:
HTTP/1.1 200 OK
$HEADER_FIELDS
{
"env": "$DUMP_OF_ENVIRONMENT_VARS",
"version": "$VERSION"
}
示例響應:
HTTP/1.1 200 OK [5/99]
Content-Length: 2471
Content-Type: application/json
Date: Mon, 24 Apr 2017 12:38:47 GMT
Etag: "5ccb76cf1545f01fd1e0df4257ff6f8da19678e9"
Server: TornadoServer/4.3
{
"env": "{'USER': 'mhausenblas', ...}"
"version": "0.5.0"
}
/info
[0.5.0+]原則回應:
HTTP/1.1 200 OK
$HEADER_FIELDS
{
"from": "$REMOTE_IP",
"host": ""$HOST:$PORT"",
"version": "$VERSION"
}
示例響應:
HTTP/1.1 200 OK
Content-Length: 67
Content-Type: application/json
Date: Mon, 24 Apr 2017 12:36:37 GMT
Etag: "9d09b0a126f68a0fddfec0f494e56fcab29eac15"
Server: TornadoServer/4.3
{
"from": "127.0.0.1",
"host": "localhost:9876",
"version": "0.5.0"
}
/health
[0.4.0+]原則回應:
HTTP/1.1 200 OK
$HEADER_FIELDS
{
"healthy": true
}
示例響應:
HTTP/1.1 200 OK
Content-Length: 17
Content-Type: application/json
Date: Tue, 11 Oct 2016 17:17:21 GMT
Etag: "b40026a9bea9f5096f4ef55d3d23d6730139ff5e"
Server: TornadoServer/4.3
{
"healthy": true
}
/endpoint0
[0.3.0+]原則回應:
HTTP/1.1 200 OK
$HEADER_FIELDS
{
"host": "$HOST:$PORT",
"result": "all is well",
"version": "$VERSION"
}
示例響應:
HTTP/1.1 200 OK
Content-Length: 71
Content-Type: application/json
Date: Tue, 11 Oct 2016 16:57:33 GMT
Etag: "ce18606c019e1d8c584b796d1fe7402d9767b9b6"
Server: TornadoServer/4.3
{
"host": "localhost:9876",
"result": "all is well",
"version": "0.4.0"
}
對於本地執行,需要Python 2.7.9
。然後,您可以像這樣運行simpleservice
:
# with defaults:
$ python simpleservice.py
# overwriting certain runtime settings:
$ HEALTH_MAX=200 VERSION=1.0 python simpleservice.py
如果您喜歡它,則可以在本地計算機上運行simpleservice
的容器版本(需要安裝Docker):
$ docker run -P mhausenblas/simpleservice:0.5.0
另請參見容器圖像。
通過設置以下環境變量,您可以更改simpleservice
的運行時行為:
PORT0
...端口simpleservice
在VERSION
... /endpoint0
endpoint的JSON響應中返回的version
的值HEALTH_MIN
和HEALTH_MAX
...最小。和最大。 /health
終點響應的毫秒延遲simpleservice
啟動後,您可以像這樣調用(以下是本地服務執行):
$ http localhost:9876/endpoint0
HTTP/1.1 200 OK
Content-Length: 71
Content-Type: application/json
Date: Tue, 11 Oct 2016 16:57:33 GMT
Etag: "ce18606c019e1d8c584b796d1fe7402d9767b9b6"
Server: TornadoServer/4.3
{
"host": "localhost:9876",
"result": "all is well",
"version": "0.4.0"
}
服務日誌將顯示以下內容:
~$ python simpleservice.py
This is a simple service in version v0.4.0 listening on port 9876
2016-10-11T05:57:33 INFO /endpoint0 serving from localhost:9876 has been invoked from 127.0.0.1 [at line 58]
2016-10-11T05:57:33 INFO 200 GET /endpoint0 (127.0.0.1) 1.10ms [at line 1946]
請注意,可用端點取決於該文檔(又稱API)中第一部分中定義的simpleservice
版本。