Skip to content

Commit

Permalink
CIRC-9934: Add support for PromQL fractional time seconds (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaifley committed Mar 14, 2023
1 parent 54111db commit 35bcde4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ to [Semantic Versioning](http://semver.org/) rules.

## [Next Release]

## [v1.13.6] - 2023-03-14

* upd: Adds support for fractional seconds for PromQL queries for compatibility.
PromQL fractional seconds are truncated when converting to CAQL queries.

## [v1.13.5] - 2023-03-14

* add: Adds support for PromQL instant queries.
Expand Down Expand Up @@ -479,6 +484,7 @@ writing to histogram endpoints.
any delay, once started. Created: 2019-03-12. Fixed: 2019-03-13.

[Next Release]: https://github.com/circonus-labs/gosnowth
[v1.13.6]: https://github.com/circonus-labs/gosnowth/releases/tag/v1.13.6
[v1.13.5]: https://github.com/circonus-labs/gosnowth/releases/tag/v1.13.5
[v1.13.4]: https://github.com/circonus-labs/gosnowth/releases/tag/v1.13.4
[v1.13.3]: https://github.com/circonus-labs/gosnowth/releases/tag/v1.13.3
Expand Down
14 changes: 7 additions & 7 deletions promql.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ func (sc *SnowthClient) PromQLInstantQueryContext(ctx context.Context,

if query.Time != "" {
if t, err := time.Parse(time.RFC3339, query.Time); err != nil {
i, err := strconv.ParseInt(query.Time, 10, 64)
f, err := strconv.ParseFloat(query.Time, 64)
if err != nil {
return nil,
fmt.Errorf("invalid PromQL query: invalid time: %v",
query.Time)
}

q.End = i
q.Start = i - 1
q.End = int64(f)
q.Start = int64(f) - 1
} else {
q.End = t.Unix()
q.Start = t.Unix() - 1
Expand Down Expand Up @@ -267,29 +267,29 @@ func (sc *SnowthClient) PromQLRangeQueryContext(ctx context.Context,

if query.Start != "" {
if t, err := time.Parse(time.RFC3339, query.Start); err != nil {
i, err := strconv.ParseInt(query.Start, 10, 64)
f, err := strconv.ParseFloat(query.Start, 64)
if err != nil {
return nil,
fmt.Errorf("invalid PromQL range query: invalid start: %v",
query.Start)
}

q.Start = i
q.Start = int64(f)
} else {
q.Start = t.Unix()
}
}

if query.End != "" {
if t, err := time.Parse(time.RFC3339, query.End); err != nil {
i, err := strconv.ParseInt(query.End, 10, 64)
f, err := strconv.ParseFloat(query.End, 64)
if err != nil {
return nil,
fmt.Errorf("invalid PromQL range query: invalid end: %v",
query.End)
}

q.End = i
q.End = int64(f)
} else {
q.End = t.Unix()
}
Expand Down
2 changes: 1 addition & 1 deletion promql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestPromQLInstantQuery(t *testing.T) {
res, err := sc.PromQLInstantQuery(&PromQLInstantQuery{
AccountID: "1",
Query: "test",
Time: "300",
Time: "300.123",
}, node)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 35bcde4

Please sign in to comment.