Skip to content

Commit

Permalink
Added timespan
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke committed Jun 30, 2024
1 parent f44e5f1 commit b0623ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/common v0.55.0
github.com/prometheus/exporter-toolkit v0.11.0
github.com/sosodev/duration v1.3.1
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4=
github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
19 changes: 18 additions & 1 deletion pkg/probe/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package probe

import (
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/sosodev/duration"
)

//nolint:cyclop
Expand Down Expand Up @@ -57,6 +59,21 @@ func GetConfigFromRequest(request *http.Request) (*Config, error) {
return nil, errors.New("'interval' parameter must be specified once")
}

if len(query["timespan"]) == 1 {
timespan, err := duration.Parse(query.Get("timespan"))
if err != nil {
return nil, fmt.Errorf("'timespan' parameter must be a ISO8601 duration: %w", err)
}

endDate := time.Now()
startDate := endDate.Add(-timespan.ToTimeDuration())

probeConfig.StartTime = to.Ptr(startDate.Format(time.RFC3339))
probeConfig.EndTime = to.Ptr(endDate.Format(time.RFC3339))
} else if len(query["timespan"]) > 1 {
return nil, errors.New("'timespan' parameter must be specified once")
}

if len(query["filter"]) == 1 {
probeConfig.Filter = to.Ptr(query.Get("filter"))
} else if len(query["filter"]) > 1 {
Expand Down Expand Up @@ -91,7 +108,7 @@ func GetConfigFromRequest(request *http.Request) (*Config, error) {

probeConfig.Top = to.Ptr(int32(topInt64))
} else if len(query["top"]) >= 1 {
return nil, errors.New("'top' parameter must be specified once")
probeConfig.Top = to.Ptr(int32(1000))
}

if len(query["queryCacheExpiration"]) == 1 {
Expand Down

0 comments on commit b0623ba

Please sign in to comment.