Skip to content

Commit 6aa9583

Browse files
Revert target CPU and add more metrics (#111)
* Revert target CPU and add more metrics * Typo * Review comments
1 parent 3a69020 commit 6aa9583

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

cloudbuild/app.yaml.template

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ network:
1717
- 9090/tcp
1818

1919
automatic_scaling:
20-
max_num_instances: 20
20+
max_num_instances: 40
2121
cool_down_period_sec: 300
22-
cpu_utilization:
23-
target_utilization: 0.3
2422

2523
env_variables:
2624
LEGACY_SERVER: https://{{PROJECT}}.appspot.com

handler/handler.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ func (c *Client) Nearest(rw http.ResponseWriter, req *http.Request) {
175175
status := http.StatusServiceUnavailable
176176
result.Error = v2.NewError("nearest", "Failed to lookup nearest machines", status)
177177
writeResult(rw, result.Error.Status, &result)
178-
metrics.RequestsTotal.WithLabelValues("nearest", http.StatusText(result.Error.Status)).Inc()
178+
metrics.RequestsTotal.WithLabelValues("nearest", "client location",
179+
http.StatusText(result.Error.Status)).Inc()
179180
return
180181
}
181182

@@ -185,7 +186,8 @@ func (c *Client) Nearest(rw http.ResponseWriter, req *http.Request) {
185186
if errLat != nil || errLon != nil {
186187
result.Error = v2.NewError("client", errFailedToLookupClient.Error(), http.StatusInternalServerError)
187188
writeResult(rw, result.Error.Status, &result)
188-
metrics.RequestsTotal.WithLabelValues("nearest", http.StatusText(result.Error.Status)).Inc()
189+
metrics.RequestsTotal.WithLabelValues("nearest", "parse client location",
190+
http.StatusText(result.Error.Status)).Inc()
189191
return
190192
}
191193

@@ -197,15 +199,16 @@ func (c *Client) Nearest(rw http.ResponseWriter, req *http.Request) {
197199
if err != nil {
198200
result.Error = v2.NewError("nearest", "Failed to lookup nearest machines", http.StatusInternalServerError)
199201
writeResult(rw, result.Error.Status, &result)
200-
metrics.RequestsTotal.WithLabelValues("nearest", http.StatusText(result.Error.Status)).Inc()
202+
metrics.RequestsTotal.WithLabelValues("nearest", "server location",
203+
http.StatusText(result.Error.Status)).Inc()
201204
return
202205
}
203206

204207
// Populate target URLs and write out response.
205208
c.populateURLs(targets, urls, experiment, "v2", req.Form)
206209
result.Results = targets
207210
writeResult(rw, http.StatusOK, &result)
208-
metrics.RequestsTotal.WithLabelValues("nearest", http.StatusText(http.StatusOK)).Inc()
211+
metrics.RequestsTotal.WithLabelValues("nearest", "success", http.StatusText(http.StatusOK)).Inc()
209212
}
210213

211214
// checkClientLocation looks up the client location and copies the location

handler/heartbeat.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ func (c *Client) Heartbeat(rw http.ResponseWriter, req *http.Request) {
2525
ws, err := upgrader.Upgrade(rw, req, nil)
2626
if err != nil {
2727
log.Errorf("failed to establish a connection: %v", err)
28-
metrics.RequestsTotal.WithLabelValues("heartbeat", err.Error()).Inc()
28+
metrics.RequestsTotal.WithLabelValues("heartbeat", "establish connection",
29+
"error upgrading the HTTP server connection to the WebSocket protocol").Inc()
2930
return
3031
}
31-
metrics.RequestsTotal.WithLabelValues("heartbeat", "OK").Inc()
32+
metrics.RequestsTotal.WithLabelValues("heartbeat", "establish connection", "OK").Inc()
3233
go c.handleHeartbeats(ws)
3334
}
3435

heartbeat/heartbeat.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,16 @@ func (h *heartbeatStatusTracker) updatePrometheusMessage(instance v2.HeartbeatMe
161161
func (h *heartbeatStatusTracker) importMemorystore() {
162162
values, err := h.GetAll()
163163

164-
if err == nil {
165-
h.mu.Lock()
166-
defer h.mu.Unlock()
167-
h.instances = values
168-
h.updateMetrics()
164+
if err != nil {
165+
metrics.ImportMemorystoreTotal.WithLabelValues(err.Error()).Inc()
166+
return
169167
}
168+
169+
metrics.ImportMemorystoreTotal.WithLabelValues("OK").Inc()
170+
h.mu.Lock()
171+
defer h.mu.Unlock()
172+
h.instances = values
173+
h.updateMetrics()
170174
}
171175

172176
// updateMetrics updates a Prometheus Gauge with the number of healthy instances per

metrics/metrics.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616
Name: "locate_requests_total",
1717
Help: "Number of requests served by the Locate service.",
1818
},
19-
[]string{"type", "status"},
19+
[]string{"type", "condition", "status"},
2020
)
2121

2222
// AppEngineTotal counts the number of times App Engine headers are
@@ -54,6 +54,16 @@ var (
5454
[]string{"experiment"},
5555
)
5656

57+
// ImportMemorystoreTotal counts the number of times the Locate Service has imported
58+
// the data in Memorystore.
59+
ImportMemorystoreTotal = promauto.NewCounterVec(
60+
prometheus.CounterOpts{
61+
Name: "locate_import_memorystore_total",
62+
Help: "Number of times the Locate Service has imported the data in Memorystore.",
63+
},
64+
[]string{"status"},
65+
)
66+
5767
// PrometheusHealthCollectionDuration is a histogram that tracks the latency of the
5868
// handler that collects Prometheus health signals.
5969
PrometheusHealthCollectionDuration = promauto.NewHistogramVec(

metrics/metrics_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
)
88

99
func TestLintMetrics(t *testing.T) {
10-
RequestsTotal.WithLabelValues("type", "status")
10+
RequestsTotal.WithLabelValues("type", "condition", "status")
1111
AppEngineTotal.WithLabelValues("country")
1212
CurrentHeartbeatConnections.WithLabelValues("experiment").Set(0)
1313
LocateHealthStatus.WithLabelValues("experiment").Set(0)
14+
ImportMemorystoreTotal.WithLabelValues("status")
1415
PrometheusHealthCollectionDuration.WithLabelValues("code")
1516
PortChecksTotal.WithLabelValues("status")
1617
KubernetesRequestsTotal.WithLabelValues("status")

0 commit comments

Comments
 (0)