Skip to content

Commit

Permalink
[Azure Billing] Update forecast api metrics interval (#36142)
Browse files Browse the repository at this point in the history
* Update forecast API metrics interval
  • Loading branch information
muthu-mps authored Jul 27, 2023
1 parent 6a5b09a commit 7fd27bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ automatic splitting at root level, if root level element is an array. {pull}3415
- Improve documentation for ActiveMQ module {issue}35113[35113] {pull}35558[35558]
- Fix EC2 host.cpu.usage {pull}35717[35717]
- Resolve statsd module's prematurely halting of metrics parsing upon encountering an invalid packet. {pull}35075[35075]
- Fix the gap in fetching forecast API metrics at the end of each month for Azure billing module {pull}36142[36142]

*Osquerybeat*

Expand Down
11 changes: 6 additions & 5 deletions x-pack/metricbeat/module/azure/billing/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ func usageIntervalFrom(reference time.Time) (time.Time, time.Time) {
// reference time.
//
// For example, if the reference time is 2007-01-09 09:41:00Z, the forecast period is:
// The forecast data is fetched from current day - 2 and for next 30 days.
//
// 2007-01-01T00:00:00Z -> 2007-01-31:59:59Z
// 2007-01-07T00:00:00Z -> 2007-02-05:59:59Z
func forecastIntervalFrom(reference time.Time) (time.Time, time.Time) {
referenceUTC := reference.UTC()
beginningOfMonth := time.Date(referenceUTC.Year(), referenceUTC.Month(), 1, 0, 0, 0, 0, time.UTC)
endOfMonth := beginningOfMonth.AddDate(0, 1, 0).Add(-1 * time.Second)
return beginningOfMonth, endOfMonth
referenceUTC := reference.UTC().Truncate(24 * time.Hour).Add((-48) * time.Hour)
forecastStartDate := time.Date(referenceUTC.Year(), referenceUTC.Month(), referenceUTC.Day(), 0, 0, 0, 0, time.UTC)
forecastEndDate := forecastStartDate.AddDate(0, 0, 0).Add(-1*time.Second).AddDate(0, 0, 30)
return forecastStartDate, forecastEndDate
}
4 changes: 2 additions & 2 deletions x-pack/metricbeat/module/azure/billing/billing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func TestForecastPeriodFrom(t *testing.T) {
referenceTime, err := time.Parse("2006-01-02 15:04:05", "2007-01-09 09:41:00")
assert.NoError(t, err)

expectedStartTime, err := time.Parse("2006-01-02 15:04:05", "2007-01-01 00:00:00")
expectedStartTime, err := time.Parse("2006-01-02 15:04:05", "2007-01-07 00:00:00")
assert.NoError(t, err)
expectedEndTime, err := time.Parse("2006-01-02 15:04:05", "2007-01-31 23:59:59")
expectedEndTime, err := time.Parse("2006-01-02 15:04:05", "2007-02-05 23:59:59")
assert.NoError(t, err)

actualStartTime, actualEndTime := forecastIntervalFrom(referenceTime)
Expand Down

0 comments on commit 7fd27bf

Please sign in to comment.