Skip to content

Commit 136f03c

Browse files
jaer-tsunYongli Chen
authored andcommitted
Cns telemetry (#275)
Adds telemetry capability for CNS.
1 parent a1b4da1 commit 136f03c

File tree

19 files changed

+327
-106
lines changed

19 files changed

+327
-106
lines changed

cnm/ipam/ipam.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const (
1919
// Plugin capabilities reported to libnetwork.
2020
requiresMACAddress = false
2121
requiresRequestReplay = false
22+
returnCode = 0
23+
returnStr = "Success"
2224
)
2325

2426
// IpamPlugin represents a CNM (libnetwork) IPAM plugin.
@@ -118,7 +120,7 @@ func (plugin *ipamPlugin) getCapabilities(w http.ResponseWriter, r *http.Request
118120

119121
err := plugin.Listener.Encode(w, &resp)
120122

121-
log.Response(plugin.Name, &resp, err)
123+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
122124
}
123125

124126
// Handles GetDefaultAddressSpaces requests.
@@ -135,7 +137,7 @@ func (plugin *ipamPlugin) getDefaultAddressSpaces(w http.ResponseWriter, r *http
135137

136138
err := plugin.Listener.Encode(w, &resp)
137139

138-
log.Response(plugin.Name, &resp, err)
140+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
139141
}
140142

141143
// Handles RequestPool requests.
@@ -163,7 +165,7 @@ func (plugin *ipamPlugin) requestPool(w http.ResponseWriter, r *http.Request) {
163165

164166
err = plugin.Listener.Encode(w, &resp)
165167

166-
log.Response(plugin.Name, &resp, err)
168+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
167169
}
168170

169171
// Handles ReleasePool requests.
@@ -195,7 +197,7 @@ func (plugin *ipamPlugin) releasePool(w http.ResponseWriter, r *http.Request) {
195197

196198
err = plugin.Listener.Encode(w, &resp)
197199

198-
log.Response(plugin.Name, &resp, err)
200+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
199201
}
200202

201203
// Handles GetPoolInfo requests.
@@ -234,7 +236,7 @@ func (plugin *ipamPlugin) getPoolInfo(w http.ResponseWriter, r *http.Request) {
234236

235237
err = plugin.Listener.Encode(w, &resp)
236238

237-
log.Response(plugin.Name, &resp, err)
239+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
238240
}
239241

240242
// Handles RequestAddress requests.
@@ -275,7 +277,7 @@ func (plugin *ipamPlugin) requestAddress(w http.ResponseWriter, r *http.Request)
275277

276278
err = plugin.Listener.Encode(w, &resp)
277279

278-
log.Response(plugin.Name, &resp, err)
280+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
279281
}
280282

281283
// Handles ReleaseAddress requests.
@@ -307,5 +309,5 @@ func (plugin *ipamPlugin) releaseAddress(w http.ResponseWriter, r *http.Request)
307309

308310
err = plugin.Listener.Encode(w, &resp)
309311

310-
log.Response(plugin.Name, &resp, err)
312+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
311313
}

cnm/network/network.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const (
2323

2424
// Prefix for container network interface names.
2525
containerInterfacePrefix = "eth"
26+
returnCode = 0
27+
returnStr = "Success"
2628
)
2729

2830
// NetPlugin represents a CNM (libnetwork) network plugin.
@@ -121,7 +123,7 @@ func (plugin *netPlugin) getCapabilities(w http.ResponseWriter, r *http.Request)
121123
resp := getCapabilitiesResponse{Scope: plugin.scope}
122124
err := plugin.Listener.Encode(w, &resp)
123125

124-
log.Response(plugin.Name, &resp, err)
126+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
125127
}
126128

127129
// Handles CreateNetwork requests.
@@ -175,7 +177,7 @@ func (plugin *netPlugin) createNetwork(w http.ResponseWriter, r *http.Request) {
175177
resp := createNetworkResponse{}
176178
err = plugin.Listener.Encode(w, &resp)
177179

178-
log.Response(plugin.Name, &resp, err)
180+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
179181
}
180182

181183
// Handles DeleteNetwork requests.
@@ -200,7 +202,7 @@ func (plugin *netPlugin) deleteNetwork(w http.ResponseWriter, r *http.Request) {
200202
resp := deleteNetworkResponse{}
201203
err = plugin.Listener.Encode(w, &resp)
202204

203-
log.Response(plugin.Name, &resp, err)
205+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
204206
}
205207

206208
// Handles CreateEndpoint requests.
@@ -244,7 +246,7 @@ func (plugin *netPlugin) createEndpoint(w http.ResponseWriter, r *http.Request)
244246

245247
err = plugin.Listener.Encode(w, &resp)
246248

247-
log.Response(plugin.Name, &resp, err)
249+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
248250
}
249251

250252
// Handles DeleteEndpoint requests.
@@ -269,7 +271,7 @@ func (plugin *netPlugin) deleteEndpoint(w http.ResponseWriter, r *http.Request)
269271
resp := deleteEndpointResponse{}
270272
err = plugin.Listener.Encode(w, &resp)
271273

272-
log.Response(plugin.Name, &resp, err)
274+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
273275
}
274276

275277
// Handles Join requests.
@@ -303,7 +305,7 @@ func (plugin *netPlugin) join(w http.ResponseWriter, r *http.Request) {
303305

304306
err = plugin.Listener.Encode(w, &resp)
305307

306-
log.Response(plugin.Name, &resp, err)
308+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
307309
}
308310

309311
// Handles Leave requests.
@@ -328,7 +330,7 @@ func (plugin *netPlugin) leave(w http.ResponseWriter, r *http.Request) {
328330
resp := leaveResponse{}
329331
err = plugin.Listener.Encode(w, &resp)
330332

331-
log.Response(plugin.Name, &resp, err)
333+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
332334
}
333335

334336
// Handles EndpointOperInfo requests.
@@ -353,5 +355,5 @@ func (plugin *netPlugin) endpointOperInfo(w http.ResponseWriter, r *http.Request
353355
resp := endpointOperInfoResponse{Value: epInfo.Data}
354356
err = plugin.Listener.Encode(w, &resp)
355357

356-
log.Response(plugin.Name, &resp, err)
358+
log.Response(plugin.Name, &resp, returnCode, returnStr, err)
357359
}

cnm/plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ func (plugin *Plugin) activate(w http.ResponseWriter, r *http.Request) {
124124
resp := ActivateResponse{Implements: plugin.Listener.GetEndpoints()}
125125
err := plugin.Listener.Encode(w, &resp)
126126

127-
log.Response(plugin.Name, &resp, err)
127+
log.Response(plugin.Name, &resp, 0, "Success", err)
128128
}
129129

130130
// SendErrorResponse sends and logs an error response.
131131
func (plugin *Plugin) SendErrorResponse(w http.ResponseWriter, errMsg error) {
132132
resp := errorResponse{errMsg.Error()}
133133
err := plugin.Listener.Encode(w, &resp)
134134

135-
log.Response(plugin.Name, &resp, err)
135+
log.Response(plugin.Name, &resp, 0, "Success", err)
136136
}

cns/NetworkContainerContract.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type Route struct {
8181
// SetOrchestratorTypeRequest specifies the orchestrator type for the node.
8282
type SetOrchestratorTypeRequest struct {
8383
OrchestratorType string
84+
DncPartitionKey string
8485
}
8586

8687
// CreateNetworkContainerResponse specifies response of creating a network container.

cns/cnsclient/cnsclient.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,34 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte)
4444

4545
err := json.NewEncoder(&body).Encode(payload)
4646
if err != nil {
47-
log.Printf("encoding json failed with %v", err)
47+
log.Errorf("encoding json failed with %v", err)
4848
return nil, err
4949
}
5050

5151
res, err := httpc.Post(url, "application/json", &body)
5252
if err != nil {
53-
log.Printf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
53+
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
5454
return nil, err
5555
}
5656

5757
defer res.Body.Close()
5858

5959
if res.StatusCode != http.StatusOK {
6060
errMsg := fmt.Sprintf("[Azure CNSClient] GetNetworkConfiguration invalid http status code: %v", res.StatusCode)
61-
log.Printf(errMsg)
61+
log.Errorf(errMsg)
6262
return nil, fmt.Errorf(errMsg)
6363
}
6464

6565
var resp cns.GetNetworkContainerResponse
6666

6767
err = json.NewDecoder(res.Body).Decode(&resp)
6868
if err != nil {
69-
log.Printf("[Azure CNSClient] Error received while parsing GetNetworkConfiguration response resp:%v err:%v", res.Body, err.Error())
69+
log.Errorf("[Azure CNSClient] Error received while parsing GetNetworkConfiguration response resp:%v err:%v", res.Body, err.Error())
7070
return nil, err
7171
}
7272

7373
if resp.Response.ReturnCode != 0 {
74-
log.Printf("[Azure CNSClient] GetNetworkConfiguration received error response :%v", resp.Response.Message)
74+
log.Errorf("[Azure CNSClient] GetNetworkConfiguration received error response :%v", resp.Response.Message)
7575
return nil, fmt.Errorf(resp.Response.Message)
7676
}
7777

cns/dockerclient/dockerclient.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"fmt"
1010
"net/http"
1111

12-
"github.com/Azure/azure-container-networking/platform"
1312
"github.com/Azure/azure-container-networking/cns/imdsclient"
1413
"github.com/Azure/azure-container-networking/log"
14+
"github.com/Azure/azure-container-networking/platform"
1515
)
1616

1717
const (
@@ -51,7 +51,7 @@ func (dockerClient *DockerClient) NetworkExists(networkName string) error {
5151
dockerClient.connectionURL + inspectNetworkPath + networkName)
5252

5353
if err != nil {
54-
log.Printf("[Azure CNS] Error received from http Post for docker network inspect %v %v", networkName, err.Error())
54+
log.Errorf("[Azure CNS] Error received from http Post for docker network inspect %v %v", networkName, err.Error())
5555
return err
5656
}
5757

cns/restserver/api.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,42 @@ const (
2222
UnsupportedOrchestratorType = 19
2323
UnexpectedError = 99
2424
)
25+
26+
func ReturnCodeToString(returnCode int) (s string) {
27+
switch returnCode {
28+
case Success:
29+
s = "Success"
30+
case UnsupportedNetworkType:
31+
s = "UnsupportedNetworkType"
32+
case InvalidParameter:
33+
s = "InvalidParameter"
34+
case UnreachableHost:
35+
s = "UnreachableHost"
36+
case ReservationNotFound:
37+
s = "ReservationNotFound"
38+
case MalformedSubnet:
39+
s = "MalformedSubnet"
40+
case UnreachableDockerDaemon:
41+
s = "UnreachableDockerDaemon"
42+
case UnspecifiedNetworkName:
43+
s = "UnspecifiedNetworkName"
44+
case NotFound:
45+
s = "NotFound"
46+
case AddressUnavailable:
47+
s = "AddressUnavailable"
48+
case NetworkContainerNotSpecified:
49+
s = "NetworkContainerNotSpecified"
50+
case CallToHostFailed:
51+
s = "CallToHostFailed"
52+
case UnknownContainerID:
53+
s = "UnknownContainerID"
54+
case UnsupportedOrchestratorType:
55+
s = "UnsupportedOrchestratorType"
56+
case UnexpectedError:
57+
s = "UnexpectedError"
58+
default:
59+
s = "UnknownError"
60+
}
61+
62+
return
63+
}

0 commit comments

Comments
 (0)