Compare commits

...

4 Commits

Author SHA1 Message Date
Mikkel Oscar Lyderik Larsen
e61071a36d Merge pull request #164 from zalando-incubator/openapi-fork
Use OpenAPI spec fork
2020-10-06 22:30:46 +02:00
Mikkel Oscar Lyderik Larsen
c108fab55a Use OpenAPI spec fork
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2020-10-02 11:06:21 +02:00
Mikkel Oscar Lyderik Larsen
be7567efea Fix handling of invalid/empty json response (#209)
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2020-10-02 10:57:53 +02:00
Mikkel Oscar Lyderik Larsen
b677e814be Update dependencies (#200)
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2020-10-02 10:55:42 +02:00
5 changed files with 237 additions and 28 deletions

19
go.mod
View File

@ -2,7 +2,7 @@ module github.com/zalando-incubator/kube-metrics-adapter
require (
github.com/NYTimes/gziphandler v1.0.1 // indirect
github.com/aws/aws-sdk-go v1.33.5
github.com/aws/aws-sdk-go v1.35.0
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/influxdata/influxdb-client-go v0.1.5
github.com/kubernetes-incubator/custom-metrics-apiserver v0.0.0-20200618121405-54026617ec44
@ -10,8 +10,8 @@ require (
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/onsi/gomega v1.8.1 // indirect
github.com/prometheus/client_golang v1.7.1
github.com/prometheus/common v0.10.0
github.com/sirupsen/logrus v1.6.0
github.com/prometheus/common v0.14.0
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v0.0.7
github.com/spyzhov/ajson v0.4.2
github.com/stretchr/testify v1.6.1
@ -20,12 +20,15 @@ require (
golang.org/x/tools v0.0.0-20200204192400-7124308813f3 // indirect
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e // indirect
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
k8s.io/api v0.18.5
k8s.io/apimachinery v0.18.5
k8s.io/client-go v0.18.5
k8s.io/component-base v0.18.5
k8s.io/api v0.18.8
k8s.io/apimachinery v0.18.8
k8s.io/client-go v0.18.8
k8s.io/component-base v0.18.8
k8s.io/klog v1.0.0
k8s.io/metrics v0.18.5
k8s.io/metrics v0.18.8
)
// use version that provides: https://github.com/kubernetes-sigs/custom-metrics-apiserver/pull/65
replace github.com/kubernetes-incubator/custom-metrics-apiserver => github.com/mikkeloscar/custom-metrics-apiserver v0.0.0-20200626202535-cd2d550cf55d
go 1.13

223
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -72,7 +72,7 @@ func (g *JSONPathMetricsGetter) GetMetric(metricsURL url.URL) (float64, error) {
return 0, err
}
if len(nodes) > 1 {
if len(nodes) != 1 {
return 0, fmt.Errorf("unexpected json: expected single numeric or array value")
}

View File

@ -1,6 +1,7 @@
package httpmetrics
import (
"errors"
"fmt"
"net/http"
"net/http/httptest"
@ -27,6 +28,7 @@ func TestJSONPathMetricsGetter(t *testing.T) {
jsonPath string
result float64
aggregator AggregatorFunc
err error
}{
{
name: "basic single value",
@ -49,6 +51,18 @@ func TestJSONPathMetricsGetter(t *testing.T) {
result: 5,
aggregator: Average,
},
{
name: "json path not resulting in array or number should lead to error",
jsonResponse: []byte(`{"metric.value":5}`),
jsonPath: "$['invalid.metric.values']",
err: errors.New("unexpected json: expected single numeric or array value"),
},
{
name: "invalid json should error",
jsonResponse: []byte(`{`),
jsonPath: "$['invalid.metric.values']",
err: errors.New("unexpected end of file"),
},
} {
t.Run(tc.name, func(t *testing.T) {
server := makeTestHTTPServer(t, tc.jsonResponse)
@ -58,6 +72,11 @@ func TestJSONPathMetricsGetter(t *testing.T) {
url, err := url.Parse(fmt.Sprintf("%s/metrics", server.URL))
require.NoError(t, err)
metric, err := getter.GetMetric(*url)
if tc.err != nil {
require.Error(t, err)
require.Equal(t, tc.err.Error(), err.Error())
return
}
require.NoError(t, err)
require.Equal(t, tc.result, metric)
})

View File

@ -126,6 +126,8 @@ func (o AdapterServerOptions) RunCustomMetricsAdapterServer(stopCh <-chan struct
return err
}
config.GenericConfig.OpenAPIConfig.Info.Title = "kube-metrics-adapter"
var clientConfig *rest.Config
if len(o.RemoteKubeConfigFile) > 0 {
loadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: o.RemoteKubeConfigFile}