This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gitops dataset configuration options
This change adds more options to the existing one (metrics chunk interval) for setting global dataset configuration using the `-startup.dataset.config` flag. This makes it a bit easier to configure and maintain these settings vs. doing it through the database directly.
- Loading branch information
1 parent
f714452
commit c8970a6
Showing
7 changed files
with
369 additions
and
40 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
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,66 @@ | ||
package dataset | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
) | ||
|
||
const ( | ||
dayUnit = 'd' | ||
unknownUnitDErrorPrefix = `time: unknown unit "d"` | ||
) | ||
|
||
// DayDuration acts like a time.Duration with support for "d" unit | ||
// which is used for specifying number of days in duration. | ||
type DayDuration time.Duration | ||
|
||
// UnmarshalText unmarshals strings into DayDuration values while | ||
// handling the day unit. It leans heavily into time.ParseDuration. | ||
func (d *DayDuration) UnmarshalText(s []byte) error { | ||
val, err := time.ParseDuration(string(s)) | ||
if err != nil { | ||
// Check for specific error indicating we are using days unit. | ||
if !strings.HasPrefix(err.Error(), unknownUnitDErrorPrefix) { | ||
return err | ||
} | ||
|
||
val, err = handleDays(s) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
*d = DayDuration(val) | ||
return nil | ||
} | ||
|
||
func handleDays(s []byte) (time.Duration, error) { | ||
parts := strings.Split(string(s), string(dayUnit)) | ||
|
||
if len(parts) > 2 { | ||
return 0, fmt.Errorf(`time: invalid duration "%s"`, string(s)) | ||
} | ||
|
||
// Treating first part as hours and multiplying with 24 to get duration in days. | ||
days, err := time.ParseDuration(parts[0] + "h") | ||
if err != nil { | ||
return 0, fmt.Errorf(`time: invalid duration "%s"`, string(s)) | ||
} | ||
days = days * 24 | ||
|
||
if s[len(s)-1] == dayUnit { | ||
return days, nil | ||
} | ||
|
||
val, err := time.ParseDuration(parts[1]) | ||
if err != nil { | ||
return 0, fmt.Errorf(`time: invalid duration "%s"`, string(s)) | ||
} | ||
|
||
return val + days, nil | ||
} | ||
|
||
// String returns a string value of DayDuration. | ||
func (d DayDuration) String() string { | ||
return time.Duration(d).String() | ||
} |
Oops, something went wrong.