Skip to content

Commit

Permalink
If the start/end times are the min/max times, don't set
Browse files Browse the repository at this point in the history
This will (with the new upstream client change) not send the start/end
to the downstream API

Fixes #528
  • Loading branch information
jacksontj committed Mar 22, 2023
1 parent 2ea06ae commit be03be8
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions pkg/promclient/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package promclient
import (
"context"
"fmt"
"math"
"time"

v1 "github.com/prometheus/client_golang/api/prometheus/v1"
Expand All @@ -14,6 +15,15 @@ import (
"github.com/jacksontj/promxy/pkg/promhttputil"
)

// Copied from prometheus' API (these should just be exported...)
// TODO: switch to model values once they are fixed
//
// https://github.com/prometheus/client_golang/issues/951
var (
minTime = time.Unix(math.MinInt64/1000+62135596801, 0).UTC()
maxTime = time.Unix(math.MaxInt64/1000-62135596801, 999999999).UTC()
)

// PromAPIV1 implements our internal API interface using *only* the v1 HTTP API
// Simply wraps the prom API to fullfil our internal API interface
type PromAPIV1 struct {
Expand All @@ -22,14 +32,53 @@ type PromAPIV1 struct {

// LabelNames returns all the unique label names present in the block in sorted order.
func (p *PromAPIV1) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error) {
// If the start or end are min/max (respectively) we want to un-set before we send those down
if startTime.Equal(minTime) {
startTime = time.Time{}
}
if endTime.Equal(maxTime) {
endTime = time.Time{}
}

return p.API.LabelNames(ctx, matchers, startTime, endTime)
}

// LabelValues performs a query for the values of the given label.
func (p *PromAPIV1) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error) {
// If the start or end are min/max (respectively) we want to un-set before we send those down
if startTime.Equal(minTime) {
startTime = time.Time{}
}
if endTime.Equal(maxTime) {
endTime = time.Time{}
}

return p.API.LabelValues(ctx, label, matchers, startTime, endTime)
}

// Query performs a query for the given time.
func (p *PromAPIV1) Query(ctx context.Context, query string, ts time.Time) (model.Value, v1.Warnings, error) {
return p.API.Query(ctx, query, ts)
}

// QueryRange performs a query for the given range.
func (p *PromAPIV1) QueryRange(ctx context.Context, query string, r v1.Range) (model.Value, v1.Warnings, error) {
return p.API.QueryRange(ctx, query, r)
}

// Series finds series by label matchers.
func (p *PromAPIV1) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error) {
// If the start or end are min/max (respectively) we want to un-set before we send those down
if startTime.Equal(minTime) {
startTime = time.Time{}
}
if endTime.Equal(maxTime) {
endTime = time.Time{}
}

return p.API.Series(ctx, matches, startTime, endTime)
}

// GetValue loads the raw data for a given set of matchers in the time range
func (p *PromAPIV1) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) (model.Value, v1.Warnings, error) {
// http://localhost:8080/api/v1/query?query=scrape_duration_seconds%7Bjob%3D%22prometheus%22%7D&time=1507412244.663&_=1507412096887
Expand Down

0 comments on commit be03be8

Please sign in to comment.