Skip to content
This repository was archived by the owner on Dec 1, 2018. It is now read-only.

Commit 4fb55d7

Browse files
committed
Use json-iterator in Kubelet client.
1 parent 847771c commit 4fb55d7

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

metrics/sources/kubelet/kubelet_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package kubelet
1919

2020
import (
2121
"bytes"
22-
"encoding/json"
2322
"fmt"
2423
"io/ioutil"
2524
"net"
@@ -30,6 +29,7 @@ import (
3029

3130
"github.com/golang/glog"
3231
cadvisor "github.com/google/cadvisor/info/v1"
32+
jsoniter "github.com/json-iterator/go"
3333
kubelet_client "k8s.io/heapster/metrics/sources/kubelet/util"
3434
stats "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
3535
)
@@ -91,7 +91,7 @@ func (self *KubeletClient) postRequestAndGetValue(client *http.Client, req *http
9191
}
9292
glog.V(10).Infof("Raw response from Kubelet at %s: %s", kubeletAddr, string(body))
9393

94-
err = json.Unmarshal(body, value)
94+
err = jsoniter.ConfigFastest.Unmarshal(body, value)
9595
if err != nil {
9696
return fmt.Errorf("failed to parse output. Response: %q. Error: %v", string(body), err)
9797
}
@@ -184,7 +184,7 @@ func (self *KubeletClient) getAllContainers(url string, start, end time.Time) ([
184184
End: end,
185185
Subcontainers: true,
186186
}
187-
body, err := json.Marshal(request)
187+
body, err := jsoniter.ConfigFastest.Marshal(request)
188188
if err != nil {
189189
return nil, err
190190
}

metrics/sources/kubelet/kubelet_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
package kubelet
1616

1717
import (
18-
"encoding/json"
1918
"net/http/httptest"
2019
"testing"
2120
"time"
2221

2322
cadvisor_api "github.com/google/cadvisor/info/v1"
23+
jsoniter "github.com/json-iterator/go"
2424
"github.com/stretchr/testify/assert"
2525
"github.com/stretchr/testify/require"
2626
util "k8s.io/client-go/util/testing"
@@ -85,7 +85,7 @@ func TestAllContainers(t *testing.T) {
8585
},
8686
},
8787
}
88-
data, err := json.Marshal(&response)
88+
data, err := jsoniter.ConfigFastest.Marshal(&response)
8989
require.NoError(t, err)
9090
handler := util.FakeHandler{
9191
StatusCode: 200,

metrics/sources/kubelet/kubelet_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package kubelet
1515

1616
import (
17-
"encoding/json"
1817
"net"
1918
"net/http/httptest"
2019
"strconv"
@@ -23,6 +22,7 @@ import (
2322
"time"
2423

2524
cadvisor_api "github.com/google/cadvisor/info/v1"
25+
jsoniter "github.com/json-iterator/go"
2626
"github.com/stretchr/testify/assert"
2727
"github.com/stretchr/testify/require"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -462,7 +462,7 @@ func TestScrapeMetrics(t *testing.T) {
462462
},
463463
},
464464
}
465-
data, err := json.Marshal(&response)
465+
data, err := jsoniter.ConfigFastest.Marshal(&response)
466466
require.NoError(t, err)
467467
handler := util.FakeHandler{
468468
StatusCode: 200,

0 commit comments

Comments
 (0)