Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lilic committed Apr 4, 2019
1 parent 8b5f899 commit 6d2bc78
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
1 change: 0 additions & 1 deletion internal/pkg/scaffold/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ const (
OLMCatalogDir = DeployDir + filePathSep + "olm-catalog"
CRDsDir = DeployDir + filePathSep + "crds"
VersionDir = "version"
MetricsDir = PkgDir + filePathSep + "metrics"
)
18 changes: 11 additions & 7 deletions internal/pkg/scaffold/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import (
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input"
)

const MetricsFile = "metrics.go"
const (
metricsFile = "metrics.go"
metricsDir = PkgDir + filePathSep + "metrics"
)

type Metrics struct {
input.Input
Expand All @@ -31,7 +34,7 @@ type Metrics struct {

func (s *Metrics) GetInput() (input.Input, error) {
if s.Path == "" {
s.Path = filepath.Join(MetricsDir, MetricsFile)
s.Path = filepath.Join(metricsDir, metricsFile)
}
s.TemplateBody = metricsPkgTemplate
return s.Input, nil
Expand All @@ -48,12 +51,13 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)
var log = logf.Log.WithName("metrics")
var resource = "{{ .Resource.APIVersion }}"
var kind = "{{ .Resource.Kind }}"
var metricName = "{{ .Resource.LowerKind }}_info"
var (
MetricFamilies = []ksmetric.FamilyGenerator{
log = logf.Log.WithName("metrics")
resource = "{{ .Resource.APIVersion }}"
kind = "{{ .Resource.Kind }}"
metricName = "{{ .Resource.LowerKind }}_info"
MetricFamilies = []ksmetric.FamilyGenerator{
ksmetric.FamilyGenerator{
Name: metricName,
Type: ksmetric.Gauge,
Expand Down
9 changes: 5 additions & 4 deletions internal/pkg/scaffold/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)
var log = logf.Log.WithName("metrics")
var resource = "app.example.com/v1alpha1"
var kind = "AppService"
var metricName = "appservice_info"
var (
log = logf.Log.WithName("metrics")
resource = "app.example.com/v1alpha1"
kind = "AppService"
metricName = "appservice_info"
MetricFamilies = []ksmetric.FamilyGenerator{
ksmetric.FamilyGenerator{
Name: metricName,
Expand Down
2 changes: 2 additions & 0 deletions pkg/kube-metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type metricHandler struct {

func (m *metricHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
resHeader := w.Header()
// 0.0.4 is the exposition format version of prometheus
// https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
resHeader.Set("Content-Type", `text/plain; version=`+"0.0.4")

for _, c := range m.collectors {
Expand Down
9 changes: 5 additions & 4 deletions pkg/kube-metrics/uclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *Client) ClientFor(apiVersion, kind, namespace string) (dynamic.Namespac

gv, err := schema.ParseGroupVersion(apiResourceList.GroupVersion)
if err != nil {
return nil, errors.Wrapf(err, "parsing GroupVersion failed %s", apiResourceList.GroupVersion)
return nil, errors.Wrapf(err, "parsing GroupVersion %s failed", apiResourceList.GroupVersion)
}

gvr := schema.GroupVersionResource{
Expand Down Expand Up @@ -89,13 +89,14 @@ func (c *Client) getAPIResource(apiVersion, kind string) (*metav1.APIResourceLis
}

func newForConfig(groupVersion string, c *rest.Config) (dynamic.Interface, error) {
config := *c
err := setConfigDefaults(groupVersion, &config)
config := rest.CopyConfig(c)

err := setConfigDefaults(groupVersion, config)
if err != nil {
return nil, err
}

return dynamic.NewForConfig(&config)
return dynamic.NewForConfig(config)
}

func setConfigDefaults(groupVersion string, config *rest.Config) error {
Expand Down

0 comments on commit 6d2bc78

Please sign in to comment.