-
Notifications
You must be signed in to change notification settings - Fork 29
bugfix: postgresql exporter delete task #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
29ec1e2
3e7ac9f
6aa564d
81e9bb6
9dc7d9e
131f4bc
eface81
02f0ce7
54a1f9c
1a07ac0
e69c231
c02aeac
af2eb5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"os" | ||
"path" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
@@ -914,32 +915,32 @@ func TestMetrics(t *testing.T) { | |
if strings.HasSuffix(*stat.Name, metrics.BlockImportTimeName) { | ||
found++ | ||
// 1 hour in seconds | ||
assert.Contains(t, stat.String(), "sample_count:1 sample_sum:3600") | ||
assert.Regexp(t, regexp.MustCompile("sample_count:1 +sample_sum:3600"), stat.String()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @winder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would guess it's related to upgrading the prometheus versions. Am I reading the regex correctly, that there is additional whitespace and some control character changes (quotes instead of angles?) but the data is otherwise the same? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. We now have |
||
} | ||
if strings.HasSuffix(*stat.Name, metrics.ImportedRoundGaugeName) { | ||
found++ | ||
assert.Contains(t, stat.String(), "value:1234") | ||
} | ||
if strings.HasSuffix(*stat.Name, metrics.ImportedTxnsPerBlockName) { | ||
found++ | ||
assert.Contains(t, stat.String(), "sample_count:1 sample_sum:14") | ||
assert.Regexp(t, regexp.MustCompile("sample_count:1 +sample_sum:14"), stat.String()) | ||
} | ||
if strings.HasSuffix(*stat.Name, metrics.ImportedTxnsName) { | ||
found++ | ||
str := stat.String() | ||
// the 6 single txns | ||
assert.Contains(t, str, `label:<name:"txn_type" value:"acfg" > gauge:<value:1 >`) | ||
assert.Contains(t, str, `label:<name:"txn_type" value:"afrz" > gauge:<value:1 >`) | ||
assert.Contains(t, str, `label:<name:"txn_type" value:"axfer" > gauge:<value:1 >`) | ||
assert.Contains(t, str, `label:<name:"txn_type" value:"keyreg" > gauge:<value:1 >`) | ||
assert.Contains(t, str, `label:<name:"txn_type" value:"pay" > gauge:<value:1 >`) | ||
assert.Contains(t, str, `label:<name:"txn_type" value:"stpf" > gauge:<value:1 >`) | ||
assert.Regexp(t, regexp.MustCompile(`label:.name:"txn_type" +value:"acfg". +gauge:.value:1.`), str) | ||
assert.Regexp(t, regexp.MustCompile(`label:.name:"txn_type" +value:"afrz". +gauge:.value:1.`), str) | ||
assert.Regexp(t, regexp.MustCompile(`label:.name:"txn_type" +value:"axfer". +gauge:.value:1.`), str) | ||
assert.Regexp(t, regexp.MustCompile(`label:.name:"txn_type" +value:"keyreg". +gauge:.value:1.`), str) | ||
assert.Regexp(t, regexp.MustCompile(`label:.name:"txn_type" +value:"pay". +gauge:.value:1.`), str) | ||
assert.Regexp(t, regexp.MustCompile(`label:.name:"txn_type" +value:"stpf". +gauge:.value:1.`), str) | ||
|
||
// 2 app call txns | ||
assert.Contains(t, str, `label:<name:"txn_type" value:"appl" > gauge:<value:2 >`) | ||
// // 2 app call txns | ||
assert.Regexp(t, regexp.MustCompile(`label:.name:"txn_type" +value:"appl". +gauge:.value:2.`), str) | ||
|
||
// 1 app had 6 inner txns | ||
assert.Contains(t, str, `label:<name:"txn_type" value:"inner" > gauge:<value:6 >`) | ||
assert.Regexp(t, regexp.MustCompile(`label:.name:"txn_type" +value:"inner". +gauge:.value:6.`), str) | ||
} | ||
} | ||
assert.Equal(t, 4, found) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import psycopg2 | ||
|
||
|
||
class IndexerDB: | ||
def __init__(self, host, port, user, password, dbname): | ||
self.host = host | ||
self.port = port | ||
self.user = user | ||
self.password = password | ||
self.dbname = dbname | ||
|
||
@classmethod | ||
def from_connection_string(cls, connection_string): | ||
init_args = { | ||
keyval.split("=")[0]: keyval.split("=")[1] | ||
for keyval in connection_string.split() | ||
} | ||
return cls( | ||
host=init_args["host"], | ||
port=init_args["port"], | ||
user=init_args["user"], | ||
password=init_args["password"], | ||
dbname=init_args["dbname"], | ||
) | ||
|
||
def select_one(self, query) -> tuple: | ||
with psycopg2.connect( | ||
host=self.host, | ||
port=self.port, | ||
user=self.user, | ||
password=self.password, | ||
dbname=self.dbname, | ||
) as connection: | ||
with connection.cursor() as cursor: | ||
cursor.execute(query) | ||
return cursor.fetchone() # type: ignore | ||
|
||
def get_txn_min_max_round(self): | ||
min_round, max_round = self.select_one("SELECT min(round), max(round) FROM txn") | ||
return min_round, max_round | ||
|
||
def get_table_row_count(self, table_name): | ||
return self.select_one(f"SELECT count(*) FROM {table_name}")[0] | ||
|
||
def get_block_header_final_round(self): | ||
return self.select_one("SELECT max(round) FROM block_header")[0] |
Uh oh!
There was an error while loading. Please reload this page.