-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'afeeb33077647181282ce3344f34f7d6c565f288' into feature/…
…traffic_processor_miniruntime_changes
- Loading branch information
Showing
13 changed files
with
364 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
libs/dao/src/main/java/com/akto/dao/traffic_metrics/RuntimeMetricsDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.akto.dao.traffic_metrics; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.bson.conversions.Bson; | ||
|
||
import com.akto.dao.AccountsContextDao; | ||
import com.akto.dao.MCollection; | ||
import com.akto.dao.context.Context; | ||
import com.akto.dto.traffic_metrics.RuntimeMetrics; | ||
import com.akto.dto.type.URLMethods; | ||
import com.akto.util.DbMode; | ||
import com.mongodb.client.MongoDatabase; | ||
import com.mongodb.client.model.CreateCollectionOptions; | ||
import com.mongodb.client.model.Filters; | ||
import com.mongodb.client.model.WriteModel; | ||
|
||
public class RuntimeMetricsDao extends AccountsContextDao<RuntimeMetrics> { | ||
|
||
public static final RuntimeMetricsDao instance = new RuntimeMetricsDao(); | ||
public static final int maxDocuments = 100_000; | ||
public static final int sizeInBytes = 100_000_000; | ||
|
||
@Override | ||
public String getCollName() { | ||
return "runtime_metrics"; | ||
} | ||
|
||
@Override | ||
public Class<RuntimeMetrics> getClassT() { | ||
return RuntimeMetrics.class; | ||
} | ||
|
||
public void createIndicesIfAbsent() { | ||
boolean exists = false; | ||
String dbName = Context.accountId.get()+""; | ||
MongoDatabase db = clients[0].getDatabase(dbName); | ||
for (String col: db.listCollectionNames()){ | ||
if (getCollName().equalsIgnoreCase(col)){ | ||
exists = true; | ||
break; | ||
} | ||
}; | ||
|
||
if (!exists) { | ||
db.createCollection(getCollName()); | ||
} | ||
|
||
if (!exists) { | ||
if (DbMode.allowCappedCollections()) { | ||
db.createCollection(getCollName(), new CreateCollectionOptions().capped(true).maxDocuments(maxDocuments).sizeInBytes(sizeInBytes)); | ||
} else { | ||
db.createCollection(getCollName()); | ||
} | ||
} | ||
|
||
MCollection.createIndexIfAbsent(getDBName(), getCollName(), | ||
new String[] { "timestamp" }, true); | ||
MCollection.createIndexIfAbsent(getDBName(), getCollName(), | ||
new String[] { "timestamp", "instanceId" }, true); | ||
} | ||
|
||
public static void bulkInsertMetrics(ArrayList<WriteModel<RuntimeMetrics>> bulkUpdates) { | ||
RuntimeMetricsDao.instance. getMCollection().bulkWrite(bulkUpdates); | ||
} | ||
|
||
public static Bson buildFilters(int startTs, int endTs) { | ||
return Filters.and( | ||
Filters.gte("timestamp", startTs), | ||
Filters.lte("timestamp", endTs) | ||
); | ||
} | ||
|
||
public static Bson buildFilters(int startTs, int endTs, String instanceId) { | ||
return Filters.and( | ||
Filters.gte("timestamp", startTs), | ||
Filters.lte("timestamp", endTs), | ||
Filters.eq("instanceId", instanceId) | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.