mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 01:38:10 +00:00
gofmt all files
Some of the files were not appropriately formatted. Now that we run `verify` in Travis, these'll need to be.
This commit is contained in:
parent
417f5a9f99
commit
756ff0941e
10 changed files with 228 additions and 227 deletions
|
|
@ -17,23 +17,23 @@ limitations under the License.
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/client-go/rest"
|
|
||||||
"k8s.io/client-go/pkg/api"
|
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
|
||||||
"k8s.io/client-go/dynamic"
|
|
||||||
"k8s.io/client-go/discovery"
|
"k8s.io/client-go/discovery"
|
||||||
|
"k8s.io/client-go/dynamic"
|
||||||
|
"k8s.io/client-go/pkg/api"
|
||||||
|
"k8s.io/client-go/rest"
|
||||||
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
|
|
||||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/cmd/server"
|
"github.com/directxman12/custom-metrics-boilerplate/pkg/cmd/server"
|
||||||
cmprov "github.com/directxman12/k8s-prometheus-adapter/pkg/custom-provider"
|
|
||||||
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||||
mprom "github.com/directxman12/k8s-prometheus-adapter/pkg/client/metrics"
|
mprom "github.com/directxman12/k8s-prometheus-adapter/pkg/client/metrics"
|
||||||
|
cmprov "github.com/directxman12/k8s-prometheus-adapter/pkg/custom-provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommandStartPrometheusAdapterServer provides a CLI handler for 'start master' command
|
// NewCommandStartPrometheusAdapterServer provides a CLI handler for 'start master' command
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,14 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"io/ioutil"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
"github.com/prometheus/common/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// APIClient is a raw client to the Prometheus Query API.
|
// APIClient is a raw client to the Prometheus Query API.
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ func (e *Error) Error() string {
|
||||||
|
|
||||||
// ResponseStatus is the type of response from the API: succeeded or error.
|
// ResponseStatus is the type of response from the API: succeeded or error.
|
||||||
type ResponseStatus string
|
type ResponseStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ResponseSucceeded ResponseStatus = "succeeded"
|
ResponseSucceeded ResponseStatus = "succeeded"
|
||||||
ResponseError = "error"
|
ResponseError = "error"
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
|
||||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
||||||
|
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||||
|
"github.com/golang/glog"
|
||||||
pmodel "github.com/prometheus/common/model"
|
pmodel "github.com/prometheus/common/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -36,6 +36,7 @@ import (
|
||||||
|
|
||||||
// SeriesType represents the kind of series backing a metric.
|
// SeriesType represents the kind of series backing a metric.
|
||||||
type SeriesType int
|
type SeriesType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CounterSeries SeriesType = iota
|
CounterSeries SeriesType = iota
|
||||||
SecondsCounterSeries
|
SecondsCounterSeries
|
||||||
|
|
@ -97,7 +98,7 @@ func (r *basicSeriesRegistry) SetSeries(newSeries []prom.Series) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
newMetrics := make([]provider.MetricInfo, 0, len(newInfo))
|
newMetrics := make([]provider.MetricInfo, 0, len(newInfo))
|
||||||
for info, _ := range newInfo {
|
for info := range newInfo {
|
||||||
newMetrics = append(newMetrics, info)
|
newMetrics = append(newMetrics, info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -324,7 +325,7 @@ func (n *metricNamer) processRootScopedSeries(series prom.Series, infos map[prov
|
||||||
func (n *metricNamer) groupResourcesFromSeries(series prom.Series) ([]schema.GroupResource, error) {
|
func (n *metricNamer) groupResourcesFromSeries(series prom.Series) ([]schema.GroupResource, error) {
|
||||||
// TODO: do we need to cache this, or is ResourceFor good enough?
|
// TODO: do we need to cache this, or is ResourceFor good enough?
|
||||||
var res []schema.GroupResource
|
var res []schema.GroupResource
|
||||||
for label, _ := range series.Labels {
|
for label := range series.Labels {
|
||||||
// TODO: figure out a way to let people specify a fully-qualified name in label-form
|
// TODO: figure out a way to let people specify a fully-qualified name in label-form
|
||||||
// TODO: will this work when missing a group?
|
// TODO: will this work when missing a group?
|
||||||
gvr, err := n.mapper.ResourceFor(schema.GroupVersionResource{Resource: string(label)})
|
gvr, err := n.mapper.ResourceFor(schema.GroupVersionResource{Resource: string(label)})
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/client-go/pkg/api"
|
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
||||||
|
pmodel "github.com/prometheus/common/model"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
"k8s.io/client-go/pkg/api"
|
||||||
pmodel "github.com/prometheus/common/model"
|
|
||||||
|
|
||||||
// install extensions so that our RESTMapper knows about it
|
// install extensions so that our RESTMapper knows about it
|
||||||
_ "k8s.io/client-go/pkg/apis/extensions/install"
|
_ "k8s.io/client-go/pkg/apis/extensions/install"
|
||||||
|
|
@ -36,7 +36,7 @@ import (
|
||||||
func setupMetricNamer(t *testing.T) *metricNamer {
|
func setupMetricNamer(t *testing.T) *metricNamer {
|
||||||
return &metricNamer{
|
return &metricNamer{
|
||||||
overrides: map[string]seriesSpec{
|
overrides: map[string]seriesSpec{
|
||||||
"container_actually_gauge_seconds_total": seriesSpec{
|
"container_actually_gauge_seconds_total": {
|
||||||
metricName: "actually_gauge",
|
metricName: "actually_gauge",
|
||||||
kind: GaugeSeries,
|
kind: GaugeSeries,
|
||||||
},
|
},
|
||||||
|
|
@ -338,21 +338,21 @@ func TestSeriesRegistry(t *testing.T) {
|
||||||
|
|
||||||
allMetrics := registry.ListAllMetrics()
|
allMetrics := registry.ListAllMetrics()
|
||||||
expectedMetrics := []provider.MetricInfo{
|
expectedMetrics := []provider.MetricInfo{
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "pods"}, true, "actually_gauge"},
|
{schema.GroupResource{Resource: "pods"}, true, "actually_gauge"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "pods"}, true, "some_usage"},
|
{schema.GroupResource{Resource: "pods"}, true, "some_usage"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "pods"}, true, "some_count"},
|
{schema.GroupResource{Resource: "pods"}, true, "some_count"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "pods"}, true, "some_time"},
|
{schema.GroupResource{Resource: "pods"}, true, "some_time"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "services"}, true, "ingress_hits"},
|
{schema.GroupResource{Resource: "services"}, true, "ingress_hits"},
|
||||||
provider.MetricInfo{schema.GroupResource{Group: "extensions", Resource: "ingresses"}, true, "ingress_hits"},
|
{schema.GroupResource{Group: "extensions", Resource: "ingresses"}, true, "ingress_hits"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "pods"}, true, "ingress_hits"},
|
{schema.GroupResource{Resource: "pods"}, true, "ingress_hits"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "namespaces"}, false, "ingress_hits"},
|
{schema.GroupResource{Resource: "namespaces"}, false, "ingress_hits"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "services"}, true, "service_proxy_packets"},
|
{schema.GroupResource{Resource: "services"}, true, "service_proxy_packets"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "namespaces"}, false, "service_proxy_packets"},
|
{schema.GroupResource{Resource: "namespaces"}, false, "service_proxy_packets"},
|
||||||
provider.MetricInfo{schema.GroupResource{Group: "extensions", Resource: "deployments"}, true, "work_queue_wait"},
|
{schema.GroupResource{Group: "extensions", Resource: "deployments"}, true, "work_queue_wait"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "namespaces"}, false, "work_queue_wait"},
|
{schema.GroupResource{Resource: "namespaces"}, false, "work_queue_wait"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "nodes"}, false, "node_gigawatts"},
|
{schema.GroupResource{Resource: "nodes"}, false, "node_gigawatts"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "persistentvolumes"}, false, "volume_claims"},
|
{schema.GroupResource{Resource: "persistentvolumes"}, false, "volume_claims"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "nodes"}, false, "node_fan"},
|
{schema.GroupResource{Resource: "nodes"}, false, "node_fan"},
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort both for easy comparison
|
// sort both for easy comparison
|
||||||
|
|
|
||||||
|
|
@ -18,27 +18,27 @@ package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
||||||
|
pmodel "github.com/prometheus/common/model"
|
||||||
apierr "k8s.io/apimachinery/pkg/api/errors"
|
apierr "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||||
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/pkg/api"
|
"k8s.io/client-go/pkg/api"
|
||||||
_ "k8s.io/client-go/pkg/api/install"
|
_ "k8s.io/client-go/pkg/api/install"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||||
"k8s.io/client-go/dynamic"
|
|
||||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
||||||
pmodel "github.com/prometheus/common/model"
|
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
||||||
|
|
||||||
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
||||||
)
|
)
|
||||||
|
|
@ -274,7 +274,6 @@ func (p *prometheusProvider) GetRootScopedMetricByName(groupResource schema.Grou
|
||||||
return p.getSingle(info, "", name)
|
return p.getSingle(info, "", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (p *prometheusProvider) GetRootScopedMetricBySelector(groupResource schema.GroupResource, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
func (p *prometheusProvider) GetRootScopedMetricBySelector(groupResource schema.GroupResource, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||||
info := provider.MetricInfo{
|
info := provider.MetricInfo{
|
||||||
GroupResource: groupResource,
|
GroupResource: groupResource,
|
||||||
|
|
|
||||||
|
|
@ -17,18 +17,18 @@ limitations under the License.
|
||||||
package provider
|
package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
|
||||||
"testing"
|
"testing"
|
||||||
"context"
|
"time"
|
||||||
|
|
||||||
fakedyn "k8s.io/client-go/dynamic/fake"
|
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
||||||
"k8s.io/client-go/pkg/api"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
fakedyn "k8s.io/client-go/dynamic/fake"
|
||||||
|
"k8s.io/client-go/pkg/api"
|
||||||
|
|
||||||
// install extensions so that our RESTMapper knows about it
|
// install extensions so that our RESTMapper knows about it
|
||||||
_ "k8s.io/client-go/pkg/apis/extensions/install"
|
_ "k8s.io/client-go/pkg/apis/extensions/install"
|
||||||
|
|
@ -99,7 +99,7 @@ func setupPrometheusProvider(t *testing.T) (provider.CustomMetricsProvider, *fak
|
||||||
containerSel := prom.MatchSeries("", prom.NameMatches("^container_.*"), prom.LabelNeq("container_name", "POD"), prom.LabelNeq("namespace", ""), prom.LabelNeq("pod_name", ""))
|
containerSel := prom.MatchSeries("", prom.NameMatches("^container_.*"), prom.LabelNeq("container_name", "POD"), prom.LabelNeq("namespace", ""), prom.LabelNeq("pod_name", ""))
|
||||||
namespacedSel := prom.MatchSeries("", prom.LabelNeq("namespace", ""), prom.NameNotMatches("^container_.*"))
|
namespacedSel := prom.MatchSeries("", prom.LabelNeq("namespace", ""), prom.NameNotMatches("^container_.*"))
|
||||||
fakeProm.series = map[prom.Selector][]prom.Series{
|
fakeProm.series = map[prom.Selector][]prom.Series{
|
||||||
containerSel: []prom.Series{
|
containerSel: {
|
||||||
{
|
{
|
||||||
Name: "container_actually_gauge_seconds_total",
|
Name: "container_actually_gauge_seconds_total",
|
||||||
Labels: pmodel.LabelSet{"pod_name": "somepod", "namespace": "somens", "container_name": "somecont"},
|
Labels: pmodel.LabelSet{"pod_name": "somepod", "namespace": "somens", "container_name": "somecont"},
|
||||||
|
|
@ -109,7 +109,7 @@ func setupPrometheusProvider(t *testing.T) (provider.CustomMetricsProvider, *fak
|
||||||
Labels: pmodel.LabelSet{"pod_name": "somepod", "namespace": "somens", "container_name": "somecont"},
|
Labels: pmodel.LabelSet{"pod_name": "somepod", "namespace": "somens", "container_name": "somecont"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
namespacedSel: []prom.Series{
|
namespacedSel: {
|
||||||
{
|
{
|
||||||
Name: "ingress_hits_total",
|
Name: "ingress_hits_total",
|
||||||
Labels: pmodel.LabelSet{"ingress": "someingress", "service": "somesvc", "pod": "backend1", "namespace": "somens"},
|
Labels: pmodel.LabelSet{"ingress": "someingress", "service": "somesvc", "pod": "backend1", "namespace": "somens"},
|
||||||
|
|
@ -152,16 +152,16 @@ func TestListAllMetrics(t *testing.T) {
|
||||||
sort.Sort(metricInfoSorter(actualMetrics))
|
sort.Sort(metricInfoSorter(actualMetrics))
|
||||||
|
|
||||||
expectedMetrics := []provider.MetricInfo{
|
expectedMetrics := []provider.MetricInfo{
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "pods"}, true, "actually_gauge"},
|
{schema.GroupResource{Resource: "pods"}, true, "actually_gauge"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "pods"}, true, "some_usage"},
|
{schema.GroupResource{Resource: "pods"}, true, "some_usage"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "services"}, true, "ingress_hits"},
|
{schema.GroupResource{Resource: "services"}, true, "ingress_hits"},
|
||||||
provider.MetricInfo{schema.GroupResource{Group: "extensions", Resource: "ingresses"}, true, "ingress_hits"},
|
{schema.GroupResource{Group: "extensions", Resource: "ingresses"}, true, "ingress_hits"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "pods"}, true, "ingress_hits"},
|
{schema.GroupResource{Resource: "pods"}, true, "ingress_hits"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "namespaces"}, false, "ingress_hits"},
|
{schema.GroupResource{Resource: "namespaces"}, false, "ingress_hits"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "services"}, true, "service_proxy_packets"},
|
{schema.GroupResource{Resource: "services"}, true, "service_proxy_packets"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "namespaces"}, false, "service_proxy_packets"},
|
{schema.GroupResource{Resource: "namespaces"}, false, "service_proxy_packets"},
|
||||||
provider.MetricInfo{schema.GroupResource{Group: "extensions", Resource: "deployments"}, true, "work_queue_wait"},
|
{schema.GroupResource{Group: "extensions", Resource: "deployments"}, true, "work_queue_wait"},
|
||||||
provider.MetricInfo{schema.GroupResource{Resource: "namespaces"}, false, "work_queue_wait"},
|
{schema.GroupResource{Resource: "namespaces"}, false, "work_queue_wait"},
|
||||||
}
|
}
|
||||||
sort.Sort(metricInfoSorter(expectedMetrics))
|
sort.Sort(metricInfoSorter(expectedMetrics))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue