Replace standard json encoding with jsoniter
This commit is contained in:
parent
0fd87a7e56
commit
91ae204f6c
5 changed files with 25 additions and 7 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ import (
|
|||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
|
||||
"k8s.io/ingress-nginx/internal/ingress/metric/collectors"
|
||||
|
@ -38,6 +40,9 @@ type Collector interface {
|
|||
|
||||
SetSSLExpireTime([]*ingress.Server)
|
||||
|
||||
// SetHosts sets the hostnames that are being served by the ingress controller
|
||||
SetHosts(sets.String)
|
||||
|
||||
Start()
|
||||
Stop()
|
||||
}
|
||||
|
@ -138,3 +143,7 @@ func (c *collector) Stop() {
|
|||
func (c *collector) SetSSLExpireTime(servers []*ingress.Server) {
|
||||
c.ingressController.SetSSLExpireTime(servers)
|
||||
}
|
||||
|
||||
func (c *collector) SetHosts(hosts sets.String) {
|
||||
c.socket.SetHosts(hosts)
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ package annotations
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/parnurzeal/gorequest"
|
||||
|
@ -90,7 +90,7 @@ var _ = framework.IngressNginxDescribe("Annotations - influxdb", func() {
|
|||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var results map[string][]map[string]interface{}
|
||||
json.Unmarshal([]byte(measurements), &results)
|
||||
jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(measurements), &results)
|
||||
|
||||
Expect(len(measurements)).ShouldNot(Equal(0))
|
||||
for _, elem := range results["results"] {
|
||||
|
|
Loading…
Reference in a new issue