Skip to content

Commit

Permalink
Fix metricsPath error (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-nguyen7 authored Apr 29, 2020
1 parent 43475ea commit 8988b4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ github.com/operator-framework/operator-registry v1.0.4/go.mod h1:hve6YwcjM2nGVls
github.com/operator-framework/operator-registry v1.1.1/go.mod h1:7D4WEwL+EKti5npUh4/u64DQhawCBRugp8Ql20duUb4=
github.com/operator-framework/operator-sdk v0.12.0 h1:9eAD1L8e6pPCpFCAacBUVf2eloDkRuVm29GTCOktLqQ=
github.com/operator-framework/operator-sdk v0.12.0/go.mod h1:mW8isQxiXlLCVf2E+xqflkQAVLOTbiqjndKdkKIrR0M=
github.com/operator-framework/operator-sdk v0.16.0 h1:+D61x7FjcITLzjVakzfzz5hqkkMDR+uEDMzXfyVZOw8=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
9 changes: 8 additions & 1 deletion pkg/metrics/builder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package metrics

import "github.com/prometheus/client_golang/prometheus"
import (
"strings"

"github.com/prometheus/client_golang/prometheus"
)

// Default variables for metrics-path and metrics-port.
const (
Expand Down Expand Up @@ -39,6 +43,9 @@ func (b *metricsConfigBuilder) WithPort(port string) *metricsConfigBuilder {

// WithPath updates the metrics path to the value provided by the user.
func (b *metricsConfigBuilder) WithPath(path string) *metricsConfigBuilder {
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
b.config.metricsPath = path
return b
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/metrics/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"strconv"
"strings"

monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
routev1 "github.com/openshift/api/route/v1"
Expand All @@ -38,6 +39,11 @@ var (

// GenerateService returns the static service at specified port
func GenerateService(port int32, portName string, serviceName string) (*v1.Service, error) {

// check if portname starts with "/"
if strings.HasPrefix(portName, "/") {
portName = portName[1:]
}
operatorName, err := k8sutil.GetOperatorName()
if err != nil {
return nil, err
Expand Down

0 comments on commit 8988b4c

Please sign in to comment.