Remove all stats tracking (fixes #7)

This commit is contained in:
Matthew Esposito 2023-12-30 10:22:49 -05:00
parent d86b77ab56
commit 53e8811f32
No known key found for this signature in database
6 changed files with 2 additions and 68 deletions

View File

@ -239,7 +239,6 @@ Assign a default value for each user-modifiable setting by passing environment v
| `SUBSCRIPTIONS` | `+`-delimited list of subreddits (`sub1+sub2+sub3+...`) | _(none)_ |
| `HIDE_AWARDS` | `["on", "off"]` | `off` |
| `DISABLE_VISIT_REDDIT_CONFIRMATION` | `["on", "off"]` | `off` |
| `DISABLE_STATS_COLLECTION` | Any string to disable | _(none)_ |
| `HIDE_SCORE` | `["on", "off"]` | `off` |
| `FIXED_NAVBAR` | `["on", "off"]` | `on` |

View File

@ -65,8 +65,5 @@
"REDLIB_PUSHSHIFT_FRONTEND": {
"required": false
},
"REDLIB_DISABLE_STATS_COLLECTION": {
"required": false
}
}
}

View File

@ -9,12 +9,10 @@ use once_cell::sync::Lazy;
use percent_encoding::{percent_encode, CONTROLS};
use serde_json::Value;
use std::{io, result::Result, sync::atomic::Ordering::SeqCst};
use std::{io, result::Result};
use tokio::sync::RwLock;
use crate::config;
use crate::dbg_msg;
use crate::instance_info::INSTANCE_INFO;
use crate::oauth::{token_daemon, Oauth};
use crate::server::RequestExt;
use crate::utils::format_url;
@ -158,10 +156,6 @@ fn reddit_head(path: String, quarantine: bool) -> Boxed<Result<Response<Body>, S
/// will recurse on the URL that Reddit provides in the Location HTTP header
/// in its response.
fn request(method: &'static Method, path: String, redirect: bool, quarantine: bool) -> Boxed<Result<Response<Body>, String>> {
// Increment reddit request count. This will include head requests.
if config::get_setting("REDLIB_DISABLE_STATS_COLLECTION").is_none() {
INSTANCE_INFO.reddit_requests.fetch_add(1, SeqCst);
}
// Build Reddit URL from path.
let url = format!("{}{}", REDDIT_URL_BASE, path);

View File

@ -88,10 +88,6 @@ pub struct Config {
#[serde(alias = "LIBREDDIT_ROBOTS_DISABLE_INDEXING")]
pub(crate) robots_disable_indexing: Option<String>,
#[serde(rename = "REDLIB_DISABLE_STATS_COLLECTION")]
#[serde(alias = "LIBREDDIT_DISABLE_STATS_COLLECTION")]
pub(crate) disable_stats_collection: Option<String>,
#[serde(rename = "REDLIB_PUSHSHIFT_FRONTEND")]
#[serde(alias = "LIBREDDIT_PUSHSHIFT_FRONTEND")]
pub(crate) pushshift: Option<String>,
@ -136,7 +132,6 @@ impl Config {
default_disable_visit_reddit_confirmation: parse("REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION"),
banner: parse("REDLIB_BANNER"),
robots_disable_indexing: parse("REDLIB_ROBOTS_DISABLE_INDEXING"),
disable_stats_collection: parse("REDLIB_DISABLE_STATS_COLLECTION"),
pushshift: parse("REDLIB_PUSHSHIFT_FRONTEND"),
}
}
@ -161,7 +156,6 @@ fn get_setting_from_config(name: &str, config: &Config) -> Option<String> {
"REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION" => config.default_disable_visit_reddit_confirmation.clone(),
"REDLIB_BANNER" => config.banner.clone(),
"REDLIB_ROBOTS_DISABLE_INDEXING" => config.robots_disable_indexing.clone(),
"REDLIB_DISABLE_STATS_COLLECTION" => config.disable_stats_collection.clone(),
"REDLIB_PUSHSHIFT_FRONTEND" => config.pushshift.clone(),
_ => None,
}
@ -231,35 +225,6 @@ fn test_default_subscriptions() {
assert_eq!(get_setting("REDLIB_DEFAULT_SUBSCRIPTIONS"), Some("news+bestof".into()));
}
#[test]
fn test_stats_collection_empty() {
assert_eq!(get_setting("REDLIB_DISABLE_STATS_COLLECTION"), None);
}
#[test]
#[sealed_test]
fn test_stats_collection_true() {
let config_to_write = r#"REDLIB_DISABLE_STATS_COLLECTION = "1""#;
write("redlib.toml", config_to_write).unwrap();
assert!(get_setting("REDLIB_DISABLE_STATS_COLLECTION").is_some());
}
#[test]
#[sealed_test]
fn test_stats_collection_false() {
let config_to_write = r#"REDLIB_DISABLE_STATS_COLLECTION = "0""#;
write("redlib.toml", config_to_write).unwrap();
assert!(get_setting("REDLIB_DISABLE_STATS_COLLECTION").is_some());
}
#[test]
#[sealed_test]
fn test_stats_collection_env_var() {
let config_to_write = r#"REDLIB_DISABLE_STATS_COLLECTION = "1""#;
write("redlib.toml", config_to_write).unwrap();
assert!(get_setting("REDLIB_DISABLE_STATS_COLLECTION").is_some());
}
#[test]
#[sealed_test]
fn test_pushshift() {

View File

@ -1,5 +1,3 @@
use std::sync::atomic::{AtomicU32, Ordering::SeqCst};
use crate::{
config::{Config, CONFIG},
server::RequestExt,
@ -91,8 +89,6 @@ pub struct InstanceInfo {
deploy_date: String,
compile_mode: String,
deploy_unix_ts: i64,
pub(crate) reddit_requests: AtomicU32,
pub(crate) total_requests: AtomicU32,
config: Config,
}
@ -109,8 +105,6 @@ impl InstanceInfo {
compile_mode: "Release".into(),
deploy_unix_ts: OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc()).unix_timestamp(),
config: CONFIG.clone(),
reddit_requests: AtomicU32::new(0),
total_requests: AtomicU32::new(0),
}
}
fn to_table(&self) -> String {
@ -131,9 +125,6 @@ impl InstanceInfo {
["Deploy timestamp", &self.deploy_unix_ts.to_string()],
["Compile mode", &self.compile_mode],
["SFW only", &convert(&self.config.sfw_only)],
["Disable stats collection", &convert(&self.config.disable_stats_collection)],
["Reddit request count", &self.reddit_requests.load(SeqCst).to_string()],
["Total request count", &self.total_requests.load(SeqCst).to_string()],
["Pushshift frontend", &convert(&self.config.pushshift)],
//TODO: fallback to crate::config::DEFAULT_PUSHSHIFT_FRONTEND
])
@ -171,9 +162,6 @@ impl InstanceInfo {
Deploy timestamp: {}\n
Compile mode: {}\n
SFW only: {:?}\n
Disable stats collection: {:?}\n
Reddit request count: {}\n
Total request count: {}\n
Pushshift frontend: {:?}\n
Config:\n
Banner: {:?}\n
@ -197,9 +185,6 @@ impl InstanceInfo {
self.deploy_unix_ts,
self.compile_mode,
self.config.sfw_only,
self.config.disable_stats_collection,
self.reddit_requests.load(SeqCst),
self.total_requests.load(SeqCst),
self.config.pushshift,
self.config.banner,
self.config.default_hide_awards,

View File

@ -20,11 +20,10 @@ use std::{
result::Result,
str::{from_utf8, Split},
string::ToString,
sync::atomic::Ordering::SeqCst,
};
use time::Duration;
use crate::{config, dbg_msg, instance_info::INSTANCE_INFO};
use crate::dbg_msg;
type BoxResponse = Pin<Box<dyn Future<Output = Result<Response<Body>, String>> + Send>>;
@ -235,11 +234,6 @@ impl Server {
match router.recognize(&format!("/{}{}", req.method().as_str(), path)) {
// If a route was configured for this path
Ok(found) => {
if config::get_setting("REDLIB_DISABLE_STATS_COLLECTION").is_none() {
// Add to total_requests count
INSTANCE_INFO.total_requests.fetch_add(1, SeqCst);
}
let mut parammed = req;
parammed.set_params(found.params().clone());