forked from mirror/client_golang
PR comments
Signed-off-by: Bob Shannon <bshannon@palantir.com>
This commit is contained in:
parent
fc258df5b5
commit
e3e66d0bb9
|
@ -2,8 +2,9 @@ sudo: false
|
|||
language: go
|
||||
|
||||
go:
|
||||
- 1.10.x
|
||||
- 1.x
|
||||
- 1.7.x
|
||||
- 1.8.x
|
||||
- 1.9.x
|
||||
|
||||
script:
|
||||
- go test -short ./...
|
||||
|
|
|
@ -22,13 +22,11 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/api"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/prometheus/scrape"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -52,13 +50,21 @@ const (
|
|||
// ErrorType models the different API error types.
|
||||
type ErrorType string
|
||||
|
||||
// Possible values for ErrorType.
|
||||
// HealthStatus models the health status of a scrape target.
|
||||
type HealthStatus string
|
||||
|
||||
const (
|
||||
// Possible values for ErrorType.
|
||||
ErrBadData ErrorType = "bad_data"
|
||||
ErrTimeout = "timeout"
|
||||
ErrCanceled = "canceled"
|
||||
ErrExec = "execution"
|
||||
ErrBadResponse = "bad_response"
|
||||
|
||||
// Possible values for HealthStatus.
|
||||
HealthGood HealthStatus = "up"
|
||||
HealthUnknown HealthStatus = "unknown"
|
||||
HealthBad HealthStatus = "down"
|
||||
)
|
||||
|
||||
// Error is an error returned by the API.
|
||||
|
@ -114,7 +120,7 @@ type AlertManagersResult struct {
|
|||
|
||||
// AlertManager models a configured Alert Manager.
|
||||
type AlertManager struct {
|
||||
URL *url.URL `json:"url"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// ConfigResult contains the result from querying the config endpoint.
|
||||
|
@ -123,9 +129,7 @@ type ConfigResult struct {
|
|||
}
|
||||
|
||||
// FlagsResult contains the result from querying the flag endpoint.
|
||||
type FlagsResult struct {
|
||||
Flags Flags
|
||||
}
|
||||
type FlagsResult map[string]string
|
||||
|
||||
// Flags models a set of flags that Prometheus is configured with.
|
||||
type Flags map[string]string
|
||||
|
@ -145,10 +149,10 @@ type TargetsResult struct {
|
|||
type ActiveTarget struct {
|
||||
DiscoveredLabels model.LabelSet `json:"discoveredLabels"`
|
||||
Labels model.LabelSet `json:"labels"`
|
||||
ScrapeURL *url.URL `json:"scrapeUrl"`
|
||||
ScrapeURL string `json:"scrapeUrl"`
|
||||
LastError string `json:"lastError"`
|
||||
LastScrape time.Time `json:"lastScrape"`
|
||||
Health scrape.TargetHealth `json:"health"`
|
||||
Health HealthStatus `json:"health"`
|
||||
}
|
||||
|
||||
// DroppedTarget models a dropped Prometheus scrape target.
|
||||
|
@ -165,54 +169,6 @@ type queryResult struct {
|
|||
v model.Value
|
||||
}
|
||||
|
||||
func (a *ActiveTarget) UnmarshalJSON(b []byte) error {
|
||||
v := struct {
|
||||
DiscoveredLabels model.LabelSet `json:"discoveredLabels"`
|
||||
Labels model.LabelSet `json:"labels"`
|
||||
ScrapeURL string `json:"scrapeUrl"`
|
||||
LastError string `json:"lastError"`
|
||||
LastScrape time.Time `json:"lastScrape"`
|
||||
Health scrape.TargetHealth `json:"health"`
|
||||
}{}
|
||||
|
||||
err := json.Unmarshal(b, &v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
url, err := url.Parse(v.ScrapeURL)
|
||||
|
||||
a.DiscoveredLabels = v.DiscoveredLabels
|
||||
a.Labels = v.Labels
|
||||
a.ScrapeURL = url
|
||||
a.LastScrape = v.LastScrape
|
||||
a.Health = v.Health
|
||||
a.LastError = v.LastError
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *AlertManager) UnmarshalJSON(b []byte) error {
|
||||
var v map[string]string
|
||||
|
||||
err := json.Unmarshal(b, &v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
url, err := url.Parse(v["url"])
|
||||
a.URL = url
|
||||
return err
|
||||
}
|
||||
|
||||
func (f *FlagsResult) UnmarshalJSON(b []byte) error {
|
||||
var v map[string]string
|
||||
|
||||
err := json.Unmarshal(b, &v)
|
||||
f.Flags = v
|
||||
return err
|
||||
}
|
||||
|
||||
func (qr *queryResult) UnmarshalJSON(b []byte) error {
|
||||
v := struct {
|
||||
Type model.ValueType `json:"resultType"`
|
||||
|
|
|
@ -27,7 +27,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/prometheus/scrape"
|
||||
)
|
||||
|
||||
type apiTest struct {
|
||||
|
@ -89,11 +88,6 @@ func TestAPIs(t *testing.T) {
|
|||
|
||||
testTime := time.Now()
|
||||
|
||||
testURL, err := url.Parse("http://127.0.0.1:9090/api/v1/alerts")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to initialize test URL.")
|
||||
}
|
||||
|
||||
client := &apiTestClient{T: t}
|
||||
|
||||
promAPI := &httpAPI{
|
||||
|
@ -372,7 +366,6 @@ func TestAPIs(t *testing.T) {
|
|||
"query.max-concurrency": "20",
|
||||
},
|
||||
res: FlagsResult{
|
||||
Flags{
|
||||
"alertmanager.notification-queue-capacity": "10000",
|
||||
"alertmanager.timeout": "10s",
|
||||
"log.level": "info",
|
||||
|
@ -380,7 +373,6 @@ func TestAPIs(t *testing.T) {
|
|||
"query.max-concurrency": "20",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
do: doFlags(),
|
||||
|
@ -397,24 +389,24 @@ func TestAPIs(t *testing.T) {
|
|||
inRes: map[string]interface{}{
|
||||
"activeAlertManagers": []map[string]string{
|
||||
{
|
||||
"url": testURL.String(),
|
||||
"url": "http://127.0.0.1:9091/api/v1/alerts",
|
||||
},
|
||||
},
|
||||
"droppedAlertManagers": []map[string]string{
|
||||
{
|
||||
"url": testURL.String(),
|
||||
"url": "http://127.0.0.1:9092/api/v1/alerts",
|
||||
},
|
||||
},
|
||||
},
|
||||
res: AlertManagersResult{
|
||||
Active: []AlertManager{
|
||||
{
|
||||
URL: testURL,
|
||||
URL: "http://127.0.0.1:9091/api/v1/alerts",
|
||||
},
|
||||
},
|
||||
Dropped: []AlertManager{
|
||||
{
|
||||
URL: testURL,
|
||||
URL: "http://127.0.0.1:9092/api/v1/alerts",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -445,7 +437,7 @@ func TestAPIs(t *testing.T) {
|
|||
"instance": "127.0.0.1:9090",
|
||||
"job": "prometheus",
|
||||
},
|
||||
"scrapeUrl": testURL.String(),
|
||||
"scrapeUrl": "http://127.0.0.1:9090",
|
||||
"lastError": "error while scraping target",
|
||||
"lastScrape": testTime.UTC().Format(time.RFC3339Nano),
|
||||
"health": "up",
|
||||
|
@ -475,10 +467,10 @@ func TestAPIs(t *testing.T) {
|
|||
"instance": "127.0.0.1:9090",
|
||||
"job": "prometheus",
|
||||
},
|
||||
ScrapeURL: testURL,
|
||||
ScrapeURL: "http://127.0.0.1:9090",
|
||||
LastError: "error while scraping target",
|
||||
LastScrape: testTime.UTC(),
|
||||
Health: scrape.HealthGood,
|
||||
Health: HealthGood,
|
||||
},
|
||||
},
|
||||
Dropped: []DroppedTarget{
|
||||
|
|
Loading…
Reference in New Issue