-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[STATS] Marking approximate points + general improvements (#836)
Approximate points marking: - New field for data point (`Point` in proto) indicating whether the data is approximate (whether it should be drawn as such). Currently all those marks are placed on trailing subsequent points. - The field is omitted for `false` values in json serialization for efficiency. Absence of the field should be treated as `false` (meaning the data is not approximate == exact) Noticeable changes in stats service: - Regardless of requested interval, no future points are now returned. - Previously they were generated according to settings; e.g. if one were to request data for 10 days forward. - Improved handling of near-today dates. - Previously was mitigated by manual removal of last point. It prevented new updated values from being shown until the end of the day. Now they will be returned as soon as they become available. - Added limit for maximum requested interval; it was possible to request server to generate data points for all days for ~ 10 000 years, which might be vulnerable to DoS (easy to fix so added just in case). The limit is configurable, default value - 500 years (max request processing time change from ~200ms to ~50ms). Other: - Development docker compose for stats service - Restructure in stats service source code to accomodate the changes - Readability improvements - Updated timestamp columns in stats db to consider timezone. Did not cause troubles yet; a preventive measure. - Pass time as argument instead of calling `..::now()` during update (for better testability)
- Loading branch information
Showing
79 changed files
with
1,604 additions
and
506 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ Dockerfile | |
README.md | ||
tests | ||
config.toml | ||
data |
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 @@ | ||
data/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,122 @@ | ||
version: '3.9' | ||
|
||
services: | ||
db-init: | ||
image: postgres:15 | ||
volumes: | ||
- ./data/blockscout-db:/var/lib/postgresql/data | ||
entrypoint: | ||
- sh | ||
- -c | ||
- | | ||
chown -R 2000:2000 /var/lib/postgresql/data | ||
db: | ||
depends_on: | ||
db-init: | ||
condition: service_completed_successfully | ||
image: postgres:15 | ||
user: 2000:2000 | ||
shm_size: 256m | ||
restart: always | ||
container_name: 'db' | ||
command: postgres -c 'max_connections=200' -c 'client_connection_check_interval=60000' | ||
environment: | ||
POSTGRES_DB: 'blockscout' | ||
POSTGRES_USER: 'blockscout' | ||
POSTGRES_PASSWORD: 'ceWb1MeLBEeOIfk65gU8EjF8' | ||
ports: | ||
- target: 5432 | ||
published: 7432 | ||
volumes: | ||
- ./data/blockscout-db:/var/lib/postgresql/data | ||
healthcheck: | ||
test: [ "CMD-SHELL", "pg_isready -U blockscout -d blockscout" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
start_period: 10s | ||
|
||
backend: | ||
depends_on: | ||
- db | ||
image: blockscout/blockscout:6.4.0 | ||
links: | ||
- db:database | ||
# extra_hosts: | ||
# - 'host.docker.internal:host-gateway' | ||
environment: | ||
DATABASE_URL: postgresql://blockscout:ceWb1MeLBEeOIfk65gU8EjF8@db:5432/blockscout | ||
ETHEREUM_JSONRPC_VARIANT: erigon | ||
ETHEREUM_JSONRPC_HTTP_URL: http://host.docker.internal:8545/ | ||
ETHEREUM_JSONRPC_TRACE_URL: http://host.docker.internal:8545/ | ||
FIRST_BLOCK: 5660029 | ||
ECTO_USE_SSL: false | ||
PORT: 4000 | ||
ports: | ||
- 80:4000 | ||
command: | ||
[ | ||
"/bin/sh", | ||
"-c", | ||
"bin/blockscout eval \"Elixir.Explorer.ReleaseTasks.create_and_migrate()\" && bin/blockscout start" | ||
] | ||
|
||
stats-db-init: | ||
image: postgres:15 | ||
volumes: | ||
- ./data/stats-db:/var/lib/postgresql/data | ||
entrypoint: | ||
- sh | ||
- -c | ||
- | | ||
chown -R 2000:2000 /var/lib/postgresql/data | ||
stats-db: | ||
depends_on: | ||
stats-db-init: | ||
condition: service_completed_successfully | ||
image: postgres:15 | ||
user: 2000:2000 | ||
shm_size: 256m | ||
restart: always | ||
container_name: 'stats-db' | ||
command: postgres -c 'max_connections=200' | ||
environment: | ||
POSTGRES_DB: 'stats' | ||
POSTGRES_USER: 'stats' | ||
POSTGRES_PASSWORD: 'n0uejXPl61ci6ldCuE2gQU5Y' | ||
ports: | ||
- target: 5432 | ||
published: 7433 | ||
volumes: | ||
- ./data/stats-db:/var/lib/postgresql/data | ||
healthcheck: | ||
test: [ "CMD-SHELL", "pg_isready -U stats -d stats" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
start_period: 10s | ||
|
||
stats: | ||
depends_on: | ||
- stats-db | ||
- backend | ||
build: . | ||
pull_policy: always | ||
platform: linux/amd64 | ||
restart: always | ||
container_name: 'stats' | ||
# extra_hosts: | ||
# - 'host.docker.internal:host-gateway' | ||
environment: | ||
- STATS__DB_URL=postgres://stats:n0uejXPl61ci6ldCuE2gQU5Y@stats-db:5432/stats | ||
- STATS__BLOCKSCOUT_DB_URL=${STATS__BLOCKSCOUT_DB_URL:-postgresql://blockscout:ceWb1MeLBEeOIfk65gU8EjF8@db:5432/blockscout} | ||
- STATS__CREATE_DATABASE=true | ||
- STATS__RUN_MIGRATIONS=true | ||
- STATS__SERVER__HTTP__ENABLED=true | ||
- STATS__SERVER__HTTP__ADDR=0.0.0.0:8050 | ||
- STATS__SERVER__HTTP__MAX_BODY_SIZE=2097152 | ||
- RUST_BACKTRACE=1 | ||
ports: | ||
- 8080:8050 |
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
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 |
---|---|---|
|
@@ -6,3 +6,6 @@ pub mod blockscout { | |
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests; |
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,39 @@ | ||
use prost::Message; | ||
|
||
use crate::blockscout::stats::v1::{self as proto}; | ||
|
||
const PRECISE_POINT_1: &str = r#" | ||
{ | ||
"date": "2024-03-14", | ||
"value": "188542399", | ||
"isApproximate": false | ||
} | ||
"#; | ||
|
||
const PRECISE_POINT_2: &str = r#" | ||
{ | ||
"date": "2024-03-14", | ||
"value": "188542399" | ||
} | ||
"#; | ||
|
||
#[test] | ||
fn is_approximate_serialization() { | ||
// deserialize | ||
let point: proto::Point = serde_json::from_str(PRECISE_POINT_1).unwrap(); | ||
assert!(!point.is_approximate); | ||
let point: proto::Point = serde_json::from_str(PRECISE_POINT_2).unwrap(); | ||
assert!(!point.is_approximate); | ||
|
||
// serialize | ||
let point = proto::Point { | ||
date: "2024-03-14".to_owned(), | ||
value: "188542399".to_owned(), | ||
is_approximate: false, | ||
}; | ||
let serialized_point = serde_json::to_string(&point).unwrap(); | ||
assert_eq!( | ||
serialized_point.replace([' ', '\n'], ""), | ||
PRECISE_POINT_2.replace([' ', '\n'], "") | ||
); | ||
} |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
use stats::DateValue; | ||
use stats::ExtendedDateValue; | ||
use stats_proto::blockscout::stats::v1::Point; | ||
|
||
pub fn serialize_line_points(data: Vec<DateValue>) -> Vec<Point> { | ||
pub fn serialize_line_points(data: Vec<ExtendedDateValue>) -> Vec<Point> { | ||
data.into_iter() | ||
.map(|point| Point { | ||
date: point.date.to_string(), | ||
value: point.value, | ||
is_approximate: point.is_approximate, | ||
}) | ||
.collect() | ||
} |
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
Oops, something went wrong.