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 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introuducing a new setting allowing to configure custom polling
intervals for individual db metric queries. The actual polling still happens on `evalInterval`, but this setting can by used to make heavier queries run less often.
- Loading branch information
Showing
7 changed files
with
155 additions
and
42 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,49 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/stretchr/testify/require" | ||
"github.com/timescale/promscale/pkg/tests/testsupport" | ||
"github.com/timescale/promscale/pkg/util" | ||
) | ||
|
||
func TestCustomPollConfig(t *testing.T) { | ||
engine := &metricsEngineImpl{ | ||
conn: testsupport.MockPgxConn{}, | ||
ctx: context.Background(), | ||
metrics: []metricQueryWrap{ | ||
{ | ||
metrics: counters( | ||
prometheus.CounterOpts{ | ||
Namespace: util.PromNamespace, | ||
Subsystem: "sql_database", | ||
Name: "test", | ||
Help: "test", | ||
}, | ||
), | ||
customPollConfig: updateAtMostEvery(1 * time.Second), | ||
query: "SELECT 1", | ||
}, | ||
}, | ||
} | ||
|
||
testStart := time.Now() | ||
testMetricPollConfig := &engine.metrics[0].customPollConfig | ||
|
||
if err := engine.Update(); err != nil { | ||
t.Fail() | ||
} | ||
require.False(t, testMetricPollConfig.lastUpdate.After(testStart)) | ||
|
||
require.Eventually(t, func() bool { | ||
if err := engine.Update(); err != nil { | ||
t.Fail() | ||
} | ||
return testMetricPollConfig.lastUpdate.After(testStart) | ||
}, 5*time.Second, 1*time.Second) | ||
|
||
} |
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,62 @@ | ||
package testsupport | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/jackc/pgconn" | ||
"github.com/jackc/pgx/v4" | ||
"github.com/jackc/pgx/v4/pgxpool" | ||
|
||
"github.com/timescale/promscale/pkg/pgxconn" | ||
) | ||
|
||
type MockRow struct{} | ||
|
||
func (MockRow) Scan(dest ...interface{}) error { return nil } | ||
|
||
type MockBatchResults struct{} | ||
|
||
func (MockBatchResults) Exec() (pgconn.CommandTag, error) { | ||
return nil, nil | ||
} | ||
|
||
func (MockBatchResults) Query() (pgx.Rows, error) { | ||
return nil, nil | ||
} | ||
func (MockBatchResults) QueryRow() pgx.Row { | ||
return MockRow{} | ||
} | ||
func (MockBatchResults) QueryFunc(scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error) { | ||
return nil, nil | ||
} | ||
func (MockBatchResults) Close() error { return nil } | ||
|
||
type MockBatch struct{} | ||
|
||
func (MockBatch) Queue(query string, arguments ...interface{}) {} | ||
func (MockBatch) Len() int { | ||
return 0 | ||
} | ||
|
||
type MockPgxConn struct{} | ||
|
||
func (MockPgxConn) Close() {} | ||
func (MockPgxConn) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error) { | ||
return pgconn.CommandTag{}, nil | ||
} | ||
func (MockPgxConn) Query(ctx context.Context, sql string, args ...interface{}) (pgxconn.PgxRows, error) { | ||
return nil, nil | ||
} | ||
func (MockPgxConn) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row { | ||
return MockRow{} | ||
} | ||
func (MockPgxConn) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error) { | ||
return 0, nil | ||
} | ||
func (MockPgxConn) CopyFromRows(rows [][]interface{}) pgx.CopyFromSource { return nil } | ||
func (MockPgxConn) NewBatch() pgxconn.PgxBatch { return MockBatch{} } | ||
func (MockPgxConn) SendBatch(ctx context.Context, b pgxconn.PgxBatch) (pgx.BatchResults, error) { | ||
return MockBatchResults{}, nil | ||
} | ||
func (MockPgxConn) Acquire(ctx context.Context) (*pgxpool.Conn, error) { return nil, nil } | ||
func (MockPgxConn) BeginTx(ctx context.Context) (pgx.Tx, error) { return nil, nil } |