This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Delay calls to Dynatrace APIs such that required data is availab…
…le (#723) * Simplify event processing logic Signed-off-by: Arthur Pitman <[email protected]> * Reorder functions Signed-off-by: Arthur Pitman <[email protected]> * Refactor getSLIResults Signed-off-by: Arthur Pitman <[email protected]> * Remove commented out imports Signed-off-by: Arthur Pitman <[email protected]> * Use ParseTimestamp from keptn/go-utils Signed-off-by: Arthur Pitman <[email protected]> * Introduce Timeframe Signed-off-by: Arthur Pitman <[email protected]> * Use Timeframe Signed-off-by: Arthur Pitman <[email protected]> * Introduce TimeframeDelay Signed-off-by: Arthur Pitman <[email protected]> * Use TimeframeDelay in Dynatrace API clients Signed-off-by: Arthur Pitman <[email protected]> * Update test Signed-off-by: Arthur Pitman <[email protected]> * Update comments for exported functions and structs Signed-off-by: Arthur Pitman <[email protected]>
- Loading branch information
1 parent
1049cd2
commit 05467e8
Showing
33 changed files
with
641 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package common | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
) | ||
|
||
// Timeframe represents a timeframe with a start and end time. | ||
type Timeframe struct { | ||
start time.Time | ||
end time.Time | ||
} | ||
|
||
// NewTimeframe creates a new timeframe from start and end times. | ||
func NewTimeframe(start time.Time, end time.Time) (*Timeframe, error) { | ||
// ensure start time is before end time | ||
if end.Sub(start).Seconds() < 0 { | ||
return nil, errors.New("error validating timeframe: start needs to be before end") | ||
} | ||
|
||
return &Timeframe{ | ||
start: start, | ||
end: end, | ||
}, nil | ||
} | ||
|
||
// Start gets the start of the timeframe. | ||
func (t Timeframe) Start() time.Time { | ||
return t.start | ||
} | ||
|
||
// End gets the end of the timeframe. | ||
func (t Timeframe) End() time.Time { | ||
return t.end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/keptn/go-utils/pkg/common/timeutils" | ||
) | ||
|
||
// TimeframeParser represents a timeframe ready to be parsed. | ||
type TimeframeParser struct { | ||
start string | ||
end string | ||
} | ||
|
||
// NewTimeframeParser creates a new TimeframeParser ready to parse the specified start and end strings. | ||
func NewTimeframeParser(start string, end string) TimeframeParser { | ||
return TimeframeParser{ | ||
start: start, | ||
end: end, | ||
} | ||
} | ||
|
||
// Parse parses the start and end strings to create a Timeframe. | ||
func (p TimeframeParser) Parse() (*Timeframe, error) { | ||
start, err := timeutils.ParseTimestamp(p.start) | ||
if err != nil { | ||
return nil, fmt.Errorf("error parsing timeframe start: %w", err) | ||
} | ||
|
||
end, err := timeutils.ParseTimestamp(p.end) | ||
if err != nil { | ||
return nil, fmt.Errorf("error parsing timeframe end: %w", err) | ||
} | ||
|
||
return NewTimeframe(*start, *end) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTimeframeParser_ValidArgs(t *testing.T) { | ||
expectedTimeframe, err := NewTimeframe(time.Date(2022, 2, 1, 10, 0, 40, 0, time.UTC), time.Date(2022, 2, 1, 10, 5, 40, 0, time.UTC)) | ||
assert.NoError(t, err) | ||
|
||
timeframe, err := NewTimeframeParser("2022-02-01T10:00:40Z", "2022-02-01T10:05:40Z").Parse() | ||
assert.NoError(t, err) | ||
|
||
assert.EqualValues(t, expectedTimeframe.Start(), timeframe.Start()) | ||
assert.EqualValues(t, expectedTimeframe.End(), timeframe.End()) | ||
} | ||
|
||
func TestTimeframeParser_InvalidStart(t *testing.T) { | ||
timeframe, err := NewTimeframeParser("", "2022-02-01T10:05:40Z").Parse() | ||
assert.Error(t, err) | ||
assert.Nil(t, timeframe) | ||
assert.Contains(t, err.Error(), "error parsing timeframe start") | ||
} | ||
|
||
func TestTimeframeParser_InvalidEnd(t *testing.T) { | ||
timeframe, err := NewTimeframeParser("2022-02-01T10:00:40Z", "").Parse() | ||
assert.Error(t, err) | ||
assert.Nil(t, timeframe) | ||
assert.Contains(t, err.Error(), "error parsing timeframe end") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewTimeframe_ValidArgs(t *testing.T) { | ||
start := time.Date(2022, 2, 1, 10, 0, 40, 0, time.UTC) | ||
end := time.Date(2022, 2, 1, 10, 5, 40, 0, time.UTC) | ||
|
||
timeframe, err := NewTimeframe(start, end) | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, start, timeframe.Start()) | ||
assert.EqualValues(t, end, timeframe.End()) | ||
} | ||
|
||
func TestNewTimeframe_InvalidEndBeforeStart(t *testing.T) { | ||
start := time.Date(2022, 2, 1, 10, 5, 40, 0, time.UTC) | ||
end := time.Date(2022, 2, 1, 10, 0, 40, 0, time.UTC) | ||
|
||
timeframe, err := NewTimeframe(start, end) | ||
assert.Error(t, err) | ||
assert.Nil(t, timeframe) | ||
assert.Contains(t, err.Error(), "error validating timeframe") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.