Skip to content

Commit

Permalink
Add support for tsdb endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Hima Varsha <hdureddy@apple.com>
  • Loading branch information
HimaVarsha94 committed Jun 24, 2020
1 parent b00f618 commit d7d98bf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
45 changes: 33 additions & 12 deletions api/prometheus/v1/api.go
Expand Up @@ -138,7 +138,7 @@ const (
epConfig = apiPrefix + "/status/config"
epFlags = apiPrefix + "/status/flags"
epRuntimeinfo = apiPrefix + "/status/runtimeinfo"
epTSDB = apiPrefix + "/status/tsdb"
epTSDB = apiPrefix + "/status/tsdb"
)

// AlertState models the state of an alert.
Expand Down Expand Up @@ -255,7 +255,7 @@ type API interface {
TargetsMetadata(ctx context.Context, matchTarget string, metric string, limit string) ([]MetricMetadata, error)
// Metadata returns metadata about metrics currently scraped by the metric name.
Metadata(ctx context.Context, metric string, limit string) (map[string][]Metadata, error)
// TSDB returns the cardinality statistics
// TSDB returns the cardinality statistics.
TSDB(ctx context.Context) (TSDBResult, error)
}

Expand Down Expand Up @@ -407,16 +407,37 @@ type queryResult struct {
v model.Value
}

// TSDBResult contains the result from querying the tsdb endpoint
// TSDBResult contains the result from querying the tsdb endpoint.
type TSDBResult struct {
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 55646ef... renaming MetricCountPair to stat
SeriesCountByMetricName []Stat `json:"seriesCountByMetricName"`
LabelValueCountByLabelName []Stat `json:"labelValueCountByLabelName"`
MemoryInBytesByLabelName []Stat `json:"memoryInBytesByLabelName"`
SeriesCountByLabelValuePair []Stat `json:"seriesCountByLabelValuePair"`
<<<<<<< HEAD
}

// Stat models information about statistic value.
type Stat struct {
=======
SeriesCountByMetricName []MetricCountPair `json:"seriesCountByMetricName"`
LabelValueCountByLabelName []MetricCountPair `json:"labelValueCountByLabelName"`
MemoryInBytesByLabelName []MetricCountPair `json:"memoryInBytesByLabelName"`
SeriesCountByLabelValuePair []MetricCountPair `json:"seriesCountByLabelValuePair"`
LabelValueCountByLabelName []MetricCountPair `json:"labelValueCountByLabelName"`
MemoryInBytesByLabelName []MetricCountPair `json:"memoryInBytesByLabelName"`
SeriesCountByLabelValuePair []MetricCountPair `json:"seriesCountByLabelValuePair"`
}

// MetricCountPair models information about metric name and count
// MetricCountPair models information about metric name and count
type MetricCountPair struct {
>>>>>>> 5f51a29... formatting bugs
=======
}

// Stat models information about statistic value.
type Stat struct {
>>>>>>> 55646ef... renaming MetricCountPair to stat
Name string `json:"name"`
Value uint64 `json:"value"`
}
Expand Down Expand Up @@ -903,20 +924,20 @@ func (h *httpAPI) Metadata(ctx context.Context, metric string, limit string) (ma
func (h *httpAPI) TSDB(ctx context.Context) (TSDBResult, error) {
u := h.client.URL(epTSDB, nil)

req, err := http.NewRequest(http.MethodGet, u.String(), nil)
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return TSDBResult{}, err
}

_, body, _, err := h.client.Do(ctx, req)
_, body, _, err := h.client.Do(ctx, req)
if err != nil {
return TSDBResult{}, err
}

var res TSDBResult
return res, json.Unmarshal(body, &res)
var res TSDBResult
return res, json.Unmarshal(body, &res)

}
}

// Warnings is an array of non critical errors
type Warnings []string
Expand Down
24 changes: 12 additions & 12 deletions api/prometheus/v1/api_test.go
Expand Up @@ -962,18 +962,18 @@ func TestAPIs(t *testing.T) {
},

{
do: doTSDB(),
reqMethod: "GET",
reqPath: "/api/v1/status/tsdb",
inErr: fmt.Errorf("some error"),
do: doTSDB(),
reqMethod: "GET",
reqPath: "/api/v1/status/tsdb",
inErr: fmt.Errorf("some error"),
err: fmt.Errorf("some error"),
},

{
do: doTSDB(),
reqMethod: "GET",
reqPath: "/api/v1/status/tsdb",
inRes:map[string]interface{}{
do: doTSDB(),
reqMethod: "GET",
reqPath: "/api/v1/status/tsdb",
inRes: map[string]interface{}{
"seriesCountByMetricName": []interface{}{
map[string]interface{}{
"name": "kubelet_http_requests_duration_seconds_bucket",
Expand All @@ -1000,25 +1000,25 @@ func TestAPIs(t *testing.T) {
},
},
res: TSDBResult{
SeriesCountByMetricName: []MetricCountPair{
SeriesCountByMetricName: []Stat{
{
Name: "kubelet_http_requests_duration_seconds_bucket",
Value: 1000,
},
},
LabelValueCountByLabelName: []MetricCountPair{
LabelValueCountByLabelName: []Stat{
{
Name: "__name__",
Value: 200,
},
},
MemoryInBytesByLabelName: []MetricCountPair{
MemoryInBytesByLabelName: []Stat{
{
Name: "id",
Value: 4096,
},
},
SeriesCountByLabelValuePair: []MetricCountPair{
SeriesCountByLabelValuePair: []Stat{
{
Name: "job=kubelet",
Value: 30000,
Expand Down

0 comments on commit d7d98bf

Please sign in to comment.