Skip to content

Commit

Permalink
reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
peekjef72 committed Sep 29, 2024
1 parent fa735ff commit b04d888
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 1 addition & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ import (
"reflect"
"regexp"

// "html/template"
"net/url"
"os"
"path/filepath"
"strings"
"text/template"
"time"

// "github.com/Masterminds/sprig/v3"
// "github.com/go-kit/log"
// "github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -276,7 +272,7 @@ func (c *Config) YAML() ([]byte, error) {
return yaml.Marshal(dc)
}

// YAML marshals the config into YAML format.
// JSON marshals the config into JSON format.
func (c *Config) JSON() ([]byte, error) {
type fullConf struct {
Config *dumpConfig `json:"config"`
Expand Down
5 changes: 3 additions & 2 deletions content.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
<body>
<div class="navbar">
<div class="navbar-header"><a href="/">Prometheus {{ .ExporterName }}</a></div>
<div><a href="/healthz">Health</a></div>
<div><a href="/health">Health</a></div>
<div><a href="{{ .MetricsPath }}">Metrics</a></div>
<div><a href="/config">Configuration</a></div>
<div><a href="/targets">Targets</a></div>
Expand Down Expand Up @@ -178,6 +178,7 @@ func HomeHandlerFunc(metricsPath string, exporter Exporter) func(http.ResponseWr
})
}
}

func HealthHandlerfunc(metricsPath string, exporter Exporter) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
var status []byte
Expand Down Expand Up @@ -318,7 +319,6 @@ func LogLevelHandlerFunc(metricsPath string, exporter Exporter, reloadCh chan<-
return
}
}

}

// StatusHandlerFunc is the HTTP handler for the `/status` page. It outputs the status of exporter.
Expand All @@ -335,6 +335,7 @@ func StatusHandlerFunc(metricsPath string, exporter Exporter) func(http.Response
StartTime: exporter.GetStartTime(),
ReloadTime: exporter.GetReloadTime(),
}

accept_type := r.Header.Get(acceptHeader)
if strings.Contains(accept_type, applicationJSON) {
res, err := json.Marshal(vinfos)
Expand Down
15 changes: 7 additions & 8 deletions promhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ func ExporterHandlerFor(exporter Exporter) http.Handler {
target Target
tmp_t *TargetConfig
)
params := req.URL.Query()

tname := params.Get("target")
if tname == "" {
params := req.URL.Query()
tname := strings.TrimSpace(params.Get("target"))
if tname == "" || tname == "template" {
err := errors.New("Target parameter is missing")
HandleError(http.StatusBadRequest, err, *metricsPath, exporter, w, req)
return
}
tname = strings.TrimSpace(tname)

target, err = exporter.FindTarget(tname)
if err == ErrTargetNotFound {
model := params.Get("model")
model = strings.TrimSpace(model)
model := strings.TrimSpace(params.Get("model"))
if model == "" {
model = "default"
}
Expand Down Expand Up @@ -120,7 +119,7 @@ func ExporterHandlerFor(exporter Exporter) http.Handler {
if err := enc.Encode(mf); err != nil {
errs = append(errs, err)
exporter.Logger().Info(
fmt.Sprintf("Error encoding metric family %q: %s", mf.GetName(), err))
fmt.Sprintf("Error encoding metric family %q: %s", mf.GetName(), err.Error()))
}
}
if closer, ok := writer.(io.Closer); ok {
Expand Down Expand Up @@ -149,7 +148,7 @@ func contextFor(req *http.Request, exporter Exporter, target Target) (context.Co
timeoutSeconds, err := strconv.ParseFloat(v, 64)
if err != nil {
exporter.Logger().Error(
fmt.Sprintf("Failed to parse timeout (`%s`) from Prometheus header: %s", v, err))
fmt.Sprintf("Failed to parse timeout (`%s`) from Prometheus header: %s", v, err.Error()))
} else {
timeout = time.Duration(timeoutSeconds * float64(time.Second))

Expand Down

0 comments on commit b04d888

Please sign in to comment.