Skip to content

Commit

Permalink
time mocker
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadnoveljic committed Jun 24, 2024
1 parent 928bb43 commit c4a7dfe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/collector/corechecks/oracle/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"

"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/benbjohnson/clock"
)

type vInstance struct {
Expand Down Expand Up @@ -150,6 +151,7 @@ func (c *Check) init() error {

c.fqtEmitted = getFqtEmittedCache()
c.planEmitted = getPlanEmittedCache(c)
c.clock = clock.New()
c.initialized = true

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/corechecks/oracle/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/DataDog/datadog-agent/pkg/util/hostname"
"github.com/DataDog/datadog-agent/pkg/util/log"
Expand Down Expand Up @@ -138,10 +137,11 @@ func (c *Check) locks() error {
}

hname, _ := hostname.Get(context.TODO())
ts := float64(c.clock.Now().UnixMilli())
m := metricsPayload{
Host: c.dbHostname,
Kind: "lock_metrics",
Timestamp: float64(time.Now().UnixMilli()),
Timestamp: ts,
MinCollectionInterval: float64(c.config.MinCollectionInterval),
Tags: c.tags,
AgentVersion: c.agentVersion,
Expand Down
6 changes: 6 additions & 0 deletions pkg/collector/corechecks/oracle/locks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/DATA-DOG/go-sqlmock"
"github.com/DataDog/datadog-agent/pkg/util/hostname"
"github.com/benbjohnson/clock"
"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -63,6 +64,10 @@ func TestLocks(t *testing.T) {
rows := sqlmock.NewRows([]string{"SECONDS", "PROGRAM"}).
AddRow(17, "test-program")
dbMock.ExpectQuery("SELECT.*transaction.*").WillReturnRows(rows)
mockClock := clock.NewMock()
mockClock.Set(time.Now())
c.clock = mockClock
ts := float64(c.clock.Now().UnixMilli())
err = c.locks()
assert.NoError(t, err, "failed to execute locks query")
payload := lockMetricsPayload{
Expand All @@ -73,6 +78,7 @@ func TestLocks(t *testing.T) {
},
},
}
m.Timestamp = ts
payload.metricsPayload = m
payloadBytes, err = json.Marshal(payload)
require.NoError(t, err, "failed to marshal lock metrics payload")
Expand Down
2 changes: 2 additions & 0 deletions pkg/collector/corechecks/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/optional"
"github.com/DataDog/datadog-agent/pkg/version"
"github.com/benbjohnson/clock"

//nolint:revive // TODO(DBM) Fix revive linter
_ "github.com/godror/godror"
Expand Down Expand Up @@ -113,6 +114,7 @@ type Check struct {
databaseRole string
openMode string
legacyIntegrationCompatibilityMode bool
clock clock.Clock
}

type vDatabase struct {
Expand Down

0 comments on commit c4a7dfe

Please sign in to comment.