-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: node population aggregation table
- Loading branch information
1 parent
e322336
commit 73a7ccf
Showing
12 changed files
with
247 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package ants | ||
|
||
import ( | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
var ( | ||
semverRegex = regexp.MustCompile(`.*(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*).*`) | ||
hexRegex = regexp.MustCompile(`^[a-fA-F0-9]+$`) | ||
) | ||
|
||
type agentVersionInfo struct { | ||
full string | ||
typ string | ||
major int | ||
minor int | ||
patch int | ||
hash string | ||
} | ||
|
||
func (avi *agentVersionInfo) Semver() [3]int { | ||
return [3]int{avi.major, avi.minor, avi.patch} | ||
} | ||
|
||
func parseAgentVersion(av string) agentVersionInfo { | ||
avi := agentVersionInfo{ | ||
full: av, | ||
} | ||
|
||
switch { | ||
case av == "": | ||
return avi | ||
case av == "celestia-celestia": | ||
avi.typ = "celestia-celestia" | ||
return avi | ||
case strings.HasPrefix(av, "celestia-node/celestia/"): | ||
// fallthrough | ||
default: | ||
avi.typ = "other" | ||
return avi | ||
} | ||
|
||
parts := strings.Split(av, "/") | ||
if len(parts) > 2 { | ||
switch parts[2] { | ||
case "bridge", "full", "light": | ||
avi.typ = parts[2] | ||
default: | ||
avi.typ = "other" | ||
} | ||
} | ||
|
||
if len(parts) > 3 { | ||
matches := semverRegex.FindStringSubmatch(parts[3]) | ||
if matches != nil { | ||
for i, name := range semverRegex.SubexpNames() { | ||
switch name { | ||
case "major": | ||
avi.major, _ = strconv.Atoi(matches[i]) | ||
case "minor": | ||
avi.minor, _ = strconv.Atoi(matches[i]) | ||
case "patch": | ||
avi.patch, _ = strconv.Atoi(matches[i]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
if len(parts) > 4 && hexRegex.MatchString(parts[4]) { | ||
avi.hash = parts[4] | ||
} | ||
|
||
return avi | ||
} |
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,113 @@ | ||
package ants | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_parseAgentVersion(t *testing.T) { | ||
tests := []struct { | ||
av string | ||
want agentVersionInfo | ||
}{ | ||
{ | ||
av: "", | ||
want: agentVersionInfo{}, | ||
}, | ||
{ | ||
av: "celestia-node/celestia/bridge/v0.17.1/078c291", | ||
want: agentVersionInfo{ | ||
full: "celestia-node/celestia/bridge/v0.17.1/078c291", | ||
typ: "bridge", | ||
major: 0, | ||
minor: 17, | ||
patch: 1, | ||
hash: "078c291", | ||
}, | ||
}, | ||
{ | ||
av: "celestia-node/celestia/full/v0.17.2/57f8bd8", | ||
want: agentVersionInfo{ | ||
full: "celestia-node/celestia/full/v0.17.2/57f8bd8", | ||
typ: "full", | ||
major: 0, | ||
minor: 17, | ||
patch: 2, | ||
hash: "57f8bd8", | ||
}, | ||
}, | ||
{ | ||
av: "celestia-node/celestia/random/v4.46.6/57f8bd8", | ||
want: agentVersionInfo{ | ||
full: "celestia-node/celestia/random/v4.46.6/57f8bd8", | ||
typ: "other", | ||
major: 4, | ||
minor: 46, | ||
patch: 6, | ||
hash: "57f8bd8", | ||
}, | ||
}, | ||
{ | ||
av: "celestia-node/celestia/light/vv0.14.0/13439cc", | ||
want: agentVersionInfo{ | ||
full: "celestia-node/celestia/light/vv0.14.0/13439cc", | ||
typ: "light", | ||
major: 0, | ||
minor: 14, | ||
patch: 0, | ||
hash: "13439cc", | ||
}, | ||
}, | ||
{ | ||
av: "celestia-node/celestia/light/v0.20.3-15-gbd3105b9/bd3105b", | ||
want: agentVersionInfo{ | ||
full: "celestia-node/celestia/light/v0.20.3-15-gbd3105b9/bd3105b", | ||
typ: "light", | ||
major: 0, | ||
minor: 20, | ||
patch: 3, | ||
hash: "bd3105b", | ||
}, | ||
}, | ||
{ | ||
av: "celestia-node/celestia/full/v0.18.0-refs-tags-v0-20-1-mocha.0/353141f", | ||
want: agentVersionInfo{ | ||
full: "celestia-node/celestia/full/v0.18.0-refs-tags-v0-20-1-mocha.0/353141f", | ||
typ: "full", | ||
major: 0, | ||
minor: 18, | ||
patch: 0, | ||
hash: "353141f", | ||
}, | ||
}, | ||
{ | ||
av: "celestia-node/celestia/light/unknown/unknown", | ||
want: agentVersionInfo{ | ||
full: "celestia-node/celestia/light/unknown/unknown", | ||
typ: "light", | ||
}, | ||
}, | ||
{ | ||
av: "celestia-celestia", | ||
want: agentVersionInfo{ | ||
full: "celestia-celestia", | ||
typ: "celestia-celestia", | ||
}, | ||
}, | ||
{ | ||
av: "celestiant", | ||
want: agentVersionInfo{ | ||
full: "celestiant", | ||
typ: "other", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.av, func(t *testing.T) { | ||
if got := parseAgentVersion(tt.av); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("parseAgentVersion() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
db/migrations/000002_alter_requests_table_add_node_type.down.sql
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,3 @@ | ||
ALTER TABLE requests | ||
DROP COLUMN IF EXISTS agent_version_type, | ||
DROP COLUMN IF EXISTS agent_version_semver; |
3 changes: 3 additions & 0 deletions
3
db/migrations/000002_alter_requests_table_add_node_type.up.sql
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,3 @@ | ||
ALTER TABLE requests | ||
ADD COLUMN agent_version_type LowCardinality(String) AFTER agent_version, | ||
ADD COLUMN agent_version_semver Array(Int16) AFTER agent_version_type; |
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 @@ | ||
DROP TABLE IF EXISTS node_population; |
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,7 @@ | ||
CREATE TABLE node_population ( | ||
timestamp DateTime, | ||
remote_multihash AggregateFunction(uniqExact, String), | ||
agent_version_type LowCardinality(String), | ||
agent_version_semver Array(Int16) | ||
) ENGINE = AggregatingMergeTree() | ||
PRIMARY KEY (timestamp, agent_version_type) |
1 change: 1 addition & 0 deletions
1
db/migrations/000004_create_node_population_materialized_view.down.sql
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 @@ | ||
DROP TABLE IF EXISTS node_population_mv; |
8 changes: 8 additions & 0 deletions
8
db/migrations/000004_create_node_population_materialized_view.up.sql
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,8 @@ | ||
CREATE MATERIALIZED VIEW node_population_mv TO node_population AS | ||
SELECT | ||
toStartOfTenMinutes(started_at) as timestamp, | ||
uniqExactState(remote_multihash) as remote_multihash, | ||
agent_version_type, | ||
agent_version_semver | ||
FROM requests | ||
GROUP BY timestamp, agent_version_type, agent_version_semver |
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 @@ | ||
ALTER TABLE requests MODIFY TTL toDateTime(started_at) + INTERVAL 180 DAY; |
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 @@ | ||
ALTER TABLE requests MODIFY TTL toDateTime(started_at) + INTERVAL 90 DAY; |
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