Skip to content

Commit 84cec24

Browse files
Openapi configuration for heartbeat (#65)
* Openapi configuration for heartbeat * Fix path * Fix indentation * Add responses * Fix path * Remove extra slash * Indentation * Revert file * Test * indentation * Test no public API * test new platform endpoint * Add cloudbuild step * Add error response * Typo * Same as existing api key endpoint * operationID * Change schemes back * Remove /platform * Add openapi-platform.yaml * Fix syntax * Delete extra period * Fix comment * Fix file name * New host for platform API * Consolidate paths under one service * Add operationId * Websocket schemes * Replace heartbeat/ with heartbeat * Group with tags * Fix tag descriptions * Revert cloudbuild
1 parent 2135ed4 commit 84cec24

File tree

9 files changed

+63
-29
lines changed

9 files changed

+63
-29
lines changed

cloudbuild/cloudbuild.yaml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,7 @@ steps:
1717
- go test ./... -race
1818
- go test -v ./...
1919

20-
# Deployment of platform specific APIs in sandbox & staging & mlab-ns.
21-
# NOTE: these services are not meant for the public, e.g. /v2/platform/*
22-
- name: gcr.io/$PROJECT_ID/gcloud-jsonnet-cbif
23-
env:
24-
# Use cbif condition: only run these steps in one of these projects.
25-
- PROJECT_IN=mlab-sandbox,mlab-staging,mlab-ns
26-
args:
27-
- cp cloudbuild/app-platform.yaml.template app-platform.yaml
28-
- >
29-
sed -i
30-
-e 's/{{PROJECT}}/$PROJECT_ID/g'
31-
-e 's/{{PLATFORM_PROJECT}}/$_PLATFORM_PROJECT/'
32-
app-platform.yaml
33-
- gcloud config set app/cloud_build_timeout 900
34-
- gcloud --project $PROJECT_ID app deploy --promote app-platform.yaml
35-
36-
# Deployment of public APIs in sandbox & staging & mlab-ns. e.g. /v2/nearest/*
20+
# Deployment of APIs in sandbox & staging & mlab-ns.
3721
- name: gcr.io/$PROJECT_ID/gcloud-jsonnet-cbif
3822
env:
3923
# Use cbif condition: only run these steps in one of these projects.

cmd/heartbeat/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ in the `-heartbeat-url` flag.
1515

1616
```sh
1717
$ go build
18-
$ ./heartbeat -heartbeat-url=ws://locate-dot-mlab-sandbox.appspot.com/v2/platform/heartbeat/
18+
$ ./heartbeat \
19+
-heartbeat-url=ws://locate-dot-mlab-sandbox.appspot.com/v2/platform/heartbeat?key=${API_KEY}
1920
```

cmd/heartbeat/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var (
2121
)
2222

2323
func init() {
24-
flag.StringVar(&heartbeatURL, "heartbeat-url", "ws://localhost:8080/v2/platform/heartbeat/",
24+
flag.StringVar(&heartbeatURL, "heartbeat-url", "ws://localhost:8080/v2/platform/heartbeat",
2525
"URL for locate service")
2626
}
2727

connection/connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ func (c *Conn) connect() error {
232232
if resp != nil {
233233
_, retry := retryErrors[resp.StatusCode]
234234
if !retry {
235-
log.Printf("error trying to establish a connection with %s, err: %v",
236-
c.url.String(), err)
235+
log.Printf("error trying to establish a connection with %s, err: %v, status: %d",
236+
c.url.String(), err, resp.StatusCode)
237237
return err
238238
}
239239
}

connection/connection_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func Test_Dial_InvalidUrl(t *testing.T) {
7979
},
8080
{
8181
name: "https-invalid-scheme",
82-
url: "https://127.0.0.2:1234/v2/heartbeat/",
82+
url: "https://127.0.0.2:1234/v2/heartbeat",
8383
},
8484
}
8585

connection/testdata/fakeserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111

1212
func FakeServer(handler func(http.ResponseWriter, *http.Request)) *httptest.Server {
1313
mux := http.NewServeMux()
14-
mux.Handle("/v2/heartbeat/", http.HandlerFunc(handler))
14+
mux.Handle("/v2/heartbeat", http.HandlerFunc(handler))
1515
s := httptest.NewServer(mux)
16-
s.URL = strings.Replace(s.URL, "http", "ws", 1) + "/v2/heartbeat/"
16+
s.URL = strings.Replace(s.URL, "http", "ws", 1) + "/v2/heartbeat"
1717
return s
1818
}
1919

handler/heartbeat_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestClient_Heartbeat_Error(t *testing.T) {
1717
rw := httptest.NewRecorder()
1818
// The header from this request will not contain the
1919
// necessary "upgrade" tokens.
20-
req := httptest.NewRequest(http.MethodGet, "/v2/heartbeat/", nil)
20+
req := httptest.NewRequest(http.MethodGet, "/v2/heartbeat", nil)
2121
c := fakeClient()
2222
c.Heartbeat(rw, req)
2323

locate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func main() {
138138
mux := http.NewServeMux()
139139
// PLATFORM APIs
140140
// Services report their health to the heartbeat service.
141-
mux.HandleFunc("/v2/platform/heartbeat/", http.HandlerFunc(c.Heartbeat))
141+
mux.HandleFunc("/v2/platform/heartbeat", http.HandlerFunc(c.Heartbeat))
142142
// End to end monitoring requests access tokens for specific targets.
143143
mux.Handle("/v2/platform/monitoring/", monitoringChain)
144144

openapi.yaml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ produces:
2929
- "application/json"
3030
schemes:
3131
- "https"
32+
- "wss"
3233

3334
paths:
3435
# DEPRECATED: original v2beta1 query for "nearest" servers.
3536
# TODO: remove once clients have migrated.
3637
"/v2beta1/query/{name}/{type}":
3738
get:
3839
description: |-
39-
DEPRECATED, use /v2/nearest/ instead.
40+
Use /v2/nearest/ instead.
4041
operationId: "v2beta1-query"
4142
produces:
4243
- "application/json"
@@ -56,6 +57,9 @@ paths:
5657
description: Nearest results.
5758
schema:
5859
$ref: "#/definitions/NearestResult"
60+
deprecated: true
61+
tags:
62+
- public
5963

6064
# Shared "nearest" requests without an API key.
6165
"/v2/nearest/{name}/{type}":
@@ -101,6 +105,8 @@ paths:
101105
request in the event of error.
102106
schema:
103107
$ref: "#/definitions/ErrorResult"
108+
tags:
109+
- public
104110

105111
# Priority "nearest" requests WITH an API key.
106112
"/v2/priority/nearest/{name}/{type}":
@@ -141,6 +147,43 @@ paths:
141147
$ref: "#/definitions/ErrorResult"
142148
security:
143149
- api_key: []
150+
tags:
151+
- public
152+
153+
"/v2/platform/heartbeat":
154+
get:
155+
description: |-
156+
Platform-specific path.
157+
operationId: "v2-platform-heartbeat"
158+
responses:
159+
'200':
160+
description: OK.
161+
security:
162+
- api_key: []
163+
tags:
164+
- platform
165+
166+
"/v2/platform/monitoring/{name}/{type}":
167+
get:
168+
description: |-
169+
Platform-specific path.
170+
operationId: "v2-platform-monitoring"
171+
parameters:
172+
- name: name
173+
in: path
174+
description: service
175+
type: string
176+
required: true
177+
- name: type
178+
in: path
179+
description: datatype
180+
type: string
181+
required: true
182+
responses:
183+
'200':
184+
description: OK.
185+
tags:
186+
- platform
144187

145188
definitions:
146189
# Define the query reply without being specific about the structure.
@@ -218,7 +261,13 @@ securityDefinitions:
218261
type: "apiKey"
219262
description: |-
220263
An API key for your client integration restricted to the Locate API and
221-
allocated using a self-service signup (TODO: link) or allocated by M-Lab
222-
for your client integration (TODO: link).
264+
allocated using a self-service [signup](https://docs.google.com/forms/d/e/1FAIpQLSeWMiPSRWHIcg5GVRG-oc5kkefLpR4Nqk4aNYBFK6Wr8jAAdw/viewform)
265+
or allocated by M-Lab for your client integration.
223266
name: "key"
224267
in: "query"
268+
269+
tags:
270+
- name: public
271+
description: Public API.
272+
- name: platform
273+
description: Platform API.

0 commit comments

Comments
 (0)