Skip to content

Commit

Permalink
fix: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Feb 19, 2024
1 parent 7fa5072 commit d73815e
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/main/java/io/supertokens/cronjobs/telemetry/Telemetry.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,25 @@ protected void doTaskPerApp(AppIdentifier app) throws Exception {
json.addProperty("telemetryId", telemetryId.value);
json.addProperty("superTokensVersion", coreVersion);

ActiveUsersStorage activeUsersStorage = (ActiveUsersStorage) StorageLayer.getStorage(
app.getAsPublicTenantIdentifier(), main);

json.addProperty("appId", app.getAppId());
json.addProperty("connectionUriDomain", app.getConnectionUriDomain());

Storage[] storages = StorageLayer.getStoragesForApp(main, app);
AppIdentifierWithStorage appIdentifierWithAllTenantStorages = new AppIdentifierWithStorage(
app.getConnectionUriDomain(), app.getAppId(),
StorageLayer.getStorage(app.getAsPublicTenantIdentifier(), main), storages
);

if (StorageLayer.getBaseStorage(main).getType() == STORAGE_TYPE.SQL) {

// Users count across all tenants
json.addProperty("usersCount", AuthRecipe.getUsersCountAcrossAllTenants(appIdentifierWithAllTenantStorages, null));
{ // Users count across all tenants
Storage[] storages = StorageLayer.getStoragesForApp(main, app);
AppIdentifierWithStorage appIdentifierWithAllTenantStorages = new AppIdentifierWithStorage(
app.getConnectionUriDomain(), app.getAppId(),
StorageLayer.getStorage(app.getAsPublicTenantIdentifier(), main), storages
);

json.addProperty("usersCount",
AuthRecipe.getUsersCountAcrossAllTenants(appIdentifierWithAllTenantStorages, null));
}

{ // Dashboard user emails
// Dashboard APIs are app specific and are always stored on the public tenant
DashboardUser[] dashboardUsers = Dashboard.getAllDashboardUsers(
appIdentifierWithAllTenantStorages, main);
app.withStorage(StorageLayer.getStorage(app.getAsPublicTenantIdentifier(), main)), main);
JsonArray dashboardUserEmails = new JsonArray();
for (DashboardUser user : dashboardUsers) {
dashboardUserEmails.add(new JsonPrimitive(user.email));
Expand All @@ -125,6 +124,10 @@ protected void doTaskPerApp(AppIdentifier app) throws Exception {
}

{ // MAUs
// Active users are always tracked on the public tenant, so we use the public tenant's storage
ActiveUsersStorage activeUsersStorage = (ActiveUsersStorage) StorageLayer.getStorage(
app.getAsPublicTenantIdentifier(), main);

JsonArray mauArr = new JsonArray();

for (int i = 0; i < 30; i++) {
Expand All @@ -143,14 +146,13 @@ protected void doTaskPerApp(AppIdentifier app) throws Exception {
json.add("maus", new JsonArray());
}


String url = "https://api.supertokens.io/0/st/telemetry";

// we call the API only if we are not testing the core, of if the request can be mocked (in case a test
// wants
// to use this)
if (!Main.isTesting || HttpRequestMocking.getInstance(main).getMockURL(REQUEST_ID, url) != null) {
HttpRequest.sendJsonPOSTRequest(main, REQUEST_ID, url, json, 10000, 10000, 4);
HttpRequest.sendJsonPOSTRequest(main, REQUEST_ID, url, json, 10000, 10000, 5);
ProcessState.getInstance(main).addState(ProcessState.PROCESS_STATE.SENT_TELEMETRY, null);
}
}
Expand Down

0 comments on commit d73815e

Please sign in to comment.