summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/instance/GitblitInstance.java
diff options
context:
space:
mode:
authorFlorian Zschocke <f.zschocke+git@gmail.com>2025-06-09 16:16:20 +0200
committerFlorian Zschocke <f.zschocke+git@gmail.com>2025-06-14 01:35:24 +0200
commit78cb19de90a56f00b8c8ca7a691d9e50e5519a95 (patch)
tree1c62e796781dbb41e34675bf4bf1350dc502e2d5 /src/main/java/com/gitblit/instance/GitblitInstance.java
parentd5526a41f0597571d94175069882bdd267bdb880 (diff)
downloadgitblit-78cb19de90a56f00b8c8ca7a691d9e50e5519a95.tar.gz
gitblit-78cb19de90a56f00b8c8ca7a691d9e50e5519a95.zip
Make sure reports are not run in test environments
Diffstat (limited to 'src/main/java/com/gitblit/instance/GitblitInstance.java')
-rw-r--r--src/main/java/com/gitblit/instance/GitblitInstance.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/instance/GitblitInstance.java b/src/main/java/com/gitblit/instance/GitblitInstance.java
index c1de69ff..48821818 100644
--- a/src/main/java/com/gitblit/instance/GitblitInstance.java
+++ b/src/main/java/com/gitblit/instance/GitblitInstance.java
@@ -1,9 +1,14 @@
package com.gitblit.instance;
+import com.gitblit.IStoredSettings;
import com.gitblit.manager.IRuntimeManager;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
public class GitblitInstance
{
+ private final static String STATS_URL = "https://instats.gitblit.dev/hiitsme/";
private IRuntimeManager runtimeManager;
@@ -50,5 +55,95 @@ public class GitblitInstance
public void start()
{
+ if (shouldRunReports()) {
+ startReports();
+ }
+ }
+
+
+ /**
+ * Determine if the reporting task should run.
+ *
+ * We do not want to report anything, i.e. the reporting task to run,
+ * if we are running unit tests or integration tests.
+ * Instance reports should only be sent for production instances or released versions.
+ * Therefore we also check if the Gitblit version is a SNAPSHOT version,
+ * or if the docker image is not a release version, when running from a docker image.
+ * A docker image running under GOSS should also not report anything.
+ */
+ boolean shouldRunReports()
+ {
+ // We can only run reports when we have been initialized
+ if (this.report == null || this.runtimeManager == null) {
+ return false;
+ }
+
+ // Check if we are running in a test environment
+ IStoredSettings settings = this.runtimeManager.getSettings();
+ if (! settings.getString("gitblit.testReportingURL", "").isEmpty()) {
+ // Force reporting to run overriding any test settings
+ return true;
+ }
+ if (settings.getBoolean("gitblit.testRun", false)) {
+ return false;
+ }
+
+ // Check if we are running a SNAPSHOT version
+ if (this.runtimeManager.getStatus().version.endsWith("SNAPSHOT")) {
+ return false;
+ }
+
+ if (this.report.instanceStat.instanceType == GitblitInstanceStat.GitblitInstanceType.DOCKER) {
+ // Check if we are running a docker image that is not a release version
+ if (! settings.getString("container.imageType", "").equals("release")) {
+ return false;
+ }
+
+ // Check if we are running a docker image under GOSS
+ if (System.getenv("GITBLIT_GOSS_TEST") != null) {
+ return false;
+ }
+ }
+
+ return true;
}
+
+
+ /**
+ * Start the reporting task.
+ *
+ * This will start a thread that runs once a day and sends the instance
+ * report to the popularity report server.
+ */
+ private void startReports()
+ {
+ this.executor = Executors.newSingleThreadScheduledExecutor();
+
+ String baseUrl = STATS_URL;
+ int delay = 24;
+ int period = 24 * 60; // 24 hours in minutes
+ TimeUnit unit = TimeUnit.MINUTES;
+
+ this.executor.scheduleAtFixedRate(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ sendMyStats(baseUrl + instanceId);
+ }
+ }, delay, period, unit);
+ }
+
+ /**
+ * Send the instance report to the popularity report server.
+ *
+ * This will send a JSON object to the server with the instance report.
+ *
+ * @param server
+ * The URL to send the report to.
+ */
+ private void sendMyStats(String server)
+ {
+ }
+
}