Skip to content
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

Report log level. #17

Merged
merged 3 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ type StatsReport struct {
TotalUsers *int64 `json:"total_users"` // Total users in users table
TotalNonBridgedUsers *int64 `json:"total_nonbridged_users"` // Total native and guest users in users table
TotalRoomCount *int64 `json:"total_room_count"` // Total number of rooms on the server
DailyActiveUsers *int64 `json:"daily_active_users"` // Total number of users in the users ips table seen in the last 24 hours
DailyActiveUsers *int64 `json:"daily_active_users"` // Total number of users in the users ips table seen in the last 24 hours
DailyMessages *int64 `json:"daily_messages"` // Total number of m.room.message in events table in the past 24 hours sent from host server
DailySentMessages *int64 `json:"daily_sent_messages"` // Total number of m.room.message in events table in the past 24 hours
DailyActiveRooms *int64 `json:"daily_active_rooms"` // Total number of rooms with a m.room.message in the event table in the past 24 hours
MonthlyActiveUsers *int64 `json:"monthly_active_users"` // Total number of users in the users ips table seen in the last 30 days
R30UsersAll *int64 `json:"r30_users_all"` // r30 stat for all users regardless of client
R30UsersAndroid *int64 `json:"r30_users_android"` // r30 stat considering only Riot Android
R30UsersIOS *int64 `json:"r30_users_ios"` // r30 stat considering only Riot iOS
Expand All @@ -68,6 +69,7 @@ type StatsReport struct {
DatabaseEngine string `json:"database_engine"`
DatabaseServerVersion string `json:"database_server_version"`
ServerContext string `json:"server_context"`
LogLevel string `json:"log_level"`
RemoteAddr string
XForwardedFor string
UserAgent string
Expand Down Expand Up @@ -129,6 +131,7 @@ func (r *Recorder) Save(sr StatsReport) error {
cols, vals = appendIfNonNil(cols, vals, "daily_active_rooms", sr.DailyActiveRooms)
cols, vals = appendIfNonNil(cols, vals, "daily_messages", sr.DailyMessages)
cols, vals = appendIfNonNil(cols, vals, "daily_sent_messages", sr.DailySentMessages)
cols, vals = appendIfNonNil(cols, vals, "monthly_active_users", sr.MonthlyActiveUsers)

cols, vals = appendIfNonNil(cols, vals, "r30_users_all", sr.R30UsersAll)
cols, vals = appendIfNonNil(cols, vals, "r30_users_android", sr.R30UsersAndroid)
Expand All @@ -153,6 +156,7 @@ func (r *Recorder) Save(sr StatsReport) error {
cols, vals = appendIfNonEmpty(cols, vals, "database_server_version", sr.DatabaseServerVersion)

cols, vals = appendIfNonEmpty(cols, vals, "server_context", sr.ServerContext)
cols, vals = appendIfNonEmpty(cols, vals, "log_level", sr.LogLevel)

var valuePlaceholders []string
for i := range vals {
Expand Down Expand Up @@ -225,6 +229,7 @@ func createTable(db *sql.DB) error {
daily_active_rooms BIGINT,
daily_messages BIGINT,
daily_sent_messages BIGINT,
monthly_active_users BIGINT,
r30_users_all BIGINT,
r30_users_android BIGINT,
r30_users_ios BIGINT,
Expand All @@ -241,7 +246,8 @@ func createTable(db *sql.DB) error {
python_version TEXT,
database_engine TEXT,
database_server_version TEXT,
server_context TEXT
server_context TEXT,
log_level TEXT
)`)

return err
Expand Down
3 changes: 3 additions & 0 deletions scripts/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def main():
`daily_active_rooms` bigint(20) DEFAULT NULL,
`daily_messages` bigint(20) DEFAULT NULL,
`daily_sent_messages` bigint(20) DEFAULT NULL,
`monthly_active_users` bigint(20) DEFAULT NULL,
`r30_users_all` bigint(20) DEFAULT NULL,
`r30_users_android` bigint(20) DEFAULT NULL,
`r30_users_ios` bigint(20) DEFAULT NULL,
Expand Down Expand Up @@ -97,6 +98,7 @@ def main():
SUM(daily_active_rooms) as 'daily_active_rooms',
SUM(daily_messages) as 'daily_messages',
SUM(daily_sent_messages) as 'daily_sent_messages',
SUM(monthly_active_users) as 'monthly_active_users',
SUM(r30_users_all) as 'r30_users_all',
SUM(r30_users_android) as 'r30_users_android',
SUM(r30_users_ios) as 'r30_users_ios',
Expand Down Expand Up @@ -130,6 +132,7 @@ def main():
daily_active_rooms,
daily_messages,
daily_sent_messages,
monthly_active_users,
r30_users_all,
r30_users_android,
r30_users_ios,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_push_good.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash -eu

. $(dirname $0)/setup.sh
log "Testing /push with beyond 0.99.2 pushes"
log "Testing /push with beyond 1.22.0 pushes"

assert_eq "{}" "$(curl -k -d '{"daily_active_users": 10, "timestamp": 20, "total_users": 123, "total_room_count": 17, "daily_messages": 9, "uptime_seconds": 19, "r30_users_all": 5, "r30_users_android": 4, "r30_users_ios": 3, "r30_users_electron": 2, "r30_users_web": 1, "daily_user_type_native": 21, "daily_user_type_guest": 22, "daily_user_type_bridged": 23, "homeserver": "many.turtles", "memory_rss": 12, "cpu_average": 125, "cache_factor": 5.501, "event_cache_size": 10000, "python_version":"3.6.1", "database_engine":"PostgreSql", "database_server_version":"9.5.0", "server_context":"my_context"}' http://localhost:${port}/push 2>/dev/null)"
assert_eq "{}" "$(curl -k -d '{"daily_active_users": 10, "timestamp": 20, "total_users": 123, "total_room_count": 17, "daily_messages": 9, "uptime_seconds": 19, "r30_users_all": 5, "r30_users_android": 4, "r30_users_ios": 3, "r30_users_electron": 2, "r30_users_web": 1, "daily_user_type_native": 21, "daily_user_type_guest": 22, "daily_user_type_bridged": 23, "homeserver": "many.turtles", "memory_rss": 12, "cpu_average": 125, "cache_factor": 5.501, "event_cache_size": 10000, "python_version":"3.6.1", "database_engine":"PostgreSql", "database_server_version":"9.5.0", "server_context":"my_context", "log_level":"INFO", "monthly_active_users": 15}' http://localhost:${port}/push 2>/dev/null)"

assert_eq "10|123|17|9|20|19|5|4|3|2|1|21|22|23|125|12|5.501|10000|3.6.1|PostgreSql|9.5.0|my_context" "$(sqlite3 ${dir}/stats.db 'SELECT daily_active_users, total_users, total_room_count, daily_messages, remote_timestamp, uptime_seconds, r30_users_all, r30_users_android, r30_users_ios, r30_users_electron, r30_users_web, daily_user_type_native, daily_user_type_guest, daily_user_type_bridged, cpu_average, memory_rss, cache_factor, event_cache_size, python_version, database_engine, database_server_version, server_context FROM stats WHERE homeserver == "many.turtles"')"
assert_eq "10|123|17|9|20|19|5|4|3|2|1|21|22|23|125|12|5.501|10000|3.6.1|PostgreSql|9.5.0|my_context|INFO|15" "$(sqlite3 ${dir}/stats.db 'SELECT daily_active_users, total_users, total_room_count, daily_messages, remote_timestamp, uptime_seconds, r30_users_all, r30_users_android, r30_users_ios, r30_users_electron, r30_users_web, daily_user_type_native, daily_user_type_guest, daily_user_type_bridged, cpu_average, memory_rss, cache_factor, event_cache_size, python_version, database_engine, database_server_version, server_context, log_level, monthly_active_users FROM stats WHERE homeserver == "many.turtles"')"


assert_eq "1" "$(sqlite3 ${dir}/stats.db 'SELECT COUNT(*) AS count FROM stats WHERE homeserver == "many.turtles" AND (remote_addr LIKE "127.0.0.1%" OR remote_addr LIKE "[::1]%")')"
Expand Down
8 changes: 8 additions & 0 deletions tests/test_push_good_before_1.22.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -eu
# You almost certainly do not want to add more tests to this file
. $(dirname $0)/setup.sh
log "Testing /push with 0.99.4 - 1.21.0 pushes"

assert_eq "{}" "$(curl -k -d '{"daily_active_users": 10, "timestamp": 20, "total_users": 123, "total_room_count": 17, "daily_messages": 9, "uptime_seconds": 19, "r30_users_all": 5, "r30_users_android": 4, "r30_users_ios": 3, "r30_users_electron": 2, "r30_users_web": 1, "daily_user_type_native": 21, "daily_user_type_guest": 22, "daily_user_type_bridged": 23, "homeserver": "many.turtles", "memory_rss": 12, "cpu_average": 125, "cache_factor": 5.501, "event_cache_size": 10000, "python_version":"3.6.1", "database_engine":"PostgreSql", "database_server_version":"9.5.0", "server_context":"my_context"}' http://localhost:${port}/push 2>/dev/null)"

assert_eq "10|123|17|9|20|19|5|4|3|2|1|21|22|23|125|12|5.501|10000|3.6.1|PostgreSql|9.5.0|my_context" "$(sqlite3 ${dir}/stats.db 'SELECT daily_active_users, total_users, total_room_count, daily_messages, remote_timestamp, uptime_seconds, r30_users_all, r30_users_android, r30_users_ios, r30_users_electron, r30_users_web, daily_user_type_native, daily_user_type_guest, daily_user_type_bridged, cpu_average, memory_rss, cache_factor, event_cache_size, python_version, database_engine, database_server_version, server_context FROM stats WHERE homeserver == "many.turtles"')"