Replace standard json encoding with jsoniter

This commit is contained in:
Manuel de Brito Fontes 2018-09-22 14:25:01 -03:00
parent 0fd87a7e56
commit 91ae204f6c
5 changed files with 25 additions and 7 deletions

View file

@ -131,7 +131,13 @@ func (n *NGINXController) syncIngress(interface{}) error {
upstreams, servers := n.getBackendServers(ings)
var passUpstreams []*ingress.SSLPassthroughBackend
hosts := sets.NewString()
for _, server := range servers {
if !hosts.Has(server.Hostname) {
hosts.Insert(server.Hostname)
}
if !server.SSLPassthrough {
continue
}
@ -184,6 +190,8 @@ func (n *NGINXController) syncIngress(interface{}) error {
return err
}
n.metricCollector.SetHosts(hosts)
glog.Infof("Backend successfully reloaded.")
n.metricCollector.ConfigSuccess(hash, true)
n.metricCollector.IncReloadCount()

View file

@ -17,7 +17,6 @@ limitations under the License.
package controller
import (
"encoding/json"
"io"
"io/ioutil"
"net"
@ -26,7 +25,9 @@ import (
"strings"
"testing"
jsoniter "github.com/json-iterator/go"
apiv1 "k8s.io/api/core/v1"
"k8s.io/ingress-nginx/internal/ingress"
)
@ -241,7 +242,7 @@ func TestConfigureCertificates(t *testing.T) {
t.Fatal(err)
}
var postedServers []ingress.Server
err = json.Unmarshal(b, &postedServers)
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(b, &postedServers)
if err != nil {
t.Fatal(err)
}

View file

@ -17,7 +17,6 @@ limitations under the License.
package template
import (
"encoding/json"
"io/ioutil"
"net"
"os"
@ -29,6 +28,7 @@ import (
"encoding/base64"
"fmt"
jsoniter "github.com/json-iterator/go"
"k8s.io/ingress-nginx/internal/file"
"k8s.io/ingress-nginx/internal/ingress"
"k8s.io/ingress-nginx/internal/ingress/annotations/authreq"
@ -518,7 +518,7 @@ func TestTemplateWithData(t *testing.T) {
t.Error("unexpected error reading json file: ", err)
}
var dat config.TemplateConfig
if err := json.Unmarshal(data, &dat); err != nil {
if err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, &dat); err != nil {
t.Errorf("unexpected error unmarshalling json: %v", err)
}
if dat.ListenPorts == nil {
@ -565,7 +565,7 @@ func BenchmarkTemplateWithData(b *testing.B) {
b.Error("unexpected error reading json file: ", err)
}
var dat config.TemplateConfig
if err := json.Unmarshal(data, &dat); err != nil {
if err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, &dat); err != nil {
b.Errorf("unexpected error unmarshalling json: %v", err)
}