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 1 commit
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
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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 @@ -153,6 +154,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 @@ -241,7 +243,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
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"}' 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" "$(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 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"')"