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

Feature/traffic processor and collector table #1513

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.akto.action.traffic_metrics;

import com.akto.action.UserAction;
import com.akto.dao.traffic_collector.TrafficCollectorInfoDao;
import com.akto.dao.traffic_collector.TrafficCollectorMetricsDao;
import com.akto.dao.traffic_metrics.RuntimeMetricsDao;
import com.akto.dao.traffic_metrics.TrafficMetricsDao;
import com.akto.dto.traffic_collector.TrafficCollectorInfo;
import com.akto.dto.traffic_collector.TrafficCollectorMetrics;
import com.akto.dto.traffic_metrics.RuntimeMetrics;
import com.akto.dto.traffic_metrics.TrafficMetrics;
import com.mongodb.BasicDBObject;
Expand Down Expand Up @@ -126,7 +130,7 @@ public String execute() {
public String fetchRuntimeInstances() {
instanceIds = new ArrayList<>();
Bson filters = RuntimeMetricsDao.buildFilters(startTimestamp, endTimestamp);
runtimeMetrics = RuntimeMetricsDao.instance.findAll(filters, 0, 0, Sorts.descending("timestamp"), Projections.include("instanceId"));
runtimeMetrics = RuntimeMetricsDao.instance.findAll(filters, 0, 0, Sorts.descending("timestamp"));
for (RuntimeMetrics metric: runtimeMetrics) {
instanceIds.add(metric.getInstanceId());
}
Expand All @@ -149,18 +153,51 @@ public String fetchRuntimeMetrics() {
while (cursor.hasNext()) {
BasicDBObject basicDBObject = cursor.next();
BasicDBObject latestDoc = (BasicDBObject) basicDBObject.get("latestDoc");
runtimeMetrics.add(new RuntimeMetrics(latestDoc.getString("name"), 0, instanceId, latestDoc.getDouble("val")));
runtimeMetrics.add(new RuntimeMetrics(latestDoc.getString("name"), 0, instanceId, latestDoc.getString("version"), latestDoc.getDouble("val")));
}
}

return SUCCESS.toUpperCase();
}

public String fetchAllRuntimeMetrics() {
Bson filters = RuntimeMetricsDao.buildFilters(startTimestamp, endTimestamp, instanceId);
runtimeMetrics = new ArrayList<>();

runtimeMetrics.addAll(RuntimeMetricsDao.instance.findAll(filters));

return SUCCESS.toUpperCase();
}

public String fetchTrafficMetricsDesciptions(){
names = Arrays.asList(TrafficMetrics.Name.values());
return SUCCESS.toUpperCase();
}

TrafficCollectorMetrics trafficCollectorMetrics;
public String fetchTrafficCollectorMetrics() {
Bson filters = Filters.and(
Filters.gte("bucketStartEpoch", startTimestamp),
Filters.lte("bucketStartEpoch", endTimestamp),
Filters.in("_id", instanceId)
);
trafficCollectorMetrics = TrafficCollectorMetricsDao.instance.findOne(filters);

return SUCCESS.toUpperCase();
}

List<TrafficCollectorInfo> trafficCollectorInfos;
public String fetchTrafficCollectorInfos() {
trafficCollectorInfos = new ArrayList<>();
Bson filters = Filters.and(
Filters.gte("startTime", startTimestamp),
Filters.lte("startTime", endTimestamp)
);
trafficCollectorInfos = TrafficCollectorInfoDao.instance.findAll(filters);

return SUCCESS.toUpperCase();
}

public void setStartTimestamp(int startTimestamp) {
this.startTimestamp = startTimestamp;
}
Expand Down Expand Up @@ -218,4 +255,20 @@ public void setInstanceId(String instanceId) {
this.instanceId = instanceId;
}

public List<TrafficCollectorInfo> getTrafficCollectorInfos() {
return trafficCollectorInfos;
}

public void setTrafficCollectorInfos(List<TrafficCollectorInfo> trafficCollectorInfos) {
this.trafficCollectorInfos = trafficCollectorInfos;
}

public TrafficCollectorMetrics getTrafficCollectorMetrics() {
return trafficCollectorMetrics;
}

public void setTrafficCollectorMetrics(TrafficCollectorMetrics trafficCollectorMetrics) {
this.trafficCollectorMetrics = trafficCollectorMetrics;
}

}
56 changes: 56 additions & 0 deletions apps/dashboard/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4996,6 +4996,17 @@
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

<action name="api/fetchAllRuntimeMetrics" class="com.akto.action.traffic_metrics.TrafficMetricsAction" method="fetchAllRuntimeMetrics">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<result name="SUCCESS" type="json"/>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

<action name="api/fetchTrafficMetricsDesciptions" class="com.akto.action.traffic_metrics.TrafficMetricsAction" method="fetchTrafficMetricsDesciptions">
<interceptor-ref name="json"/>
Expand All @@ -5020,6 +5031,51 @@
</result>
</action>

<action name="api/fetchTrafficCollectorInfos" class="com.akto.action.traffic_metrics.TrafficMetricsAction" method="fetchTrafficCollectorInfos">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<interceptor-ref name="roleAccessInterceptor">
<param name="featureLabel">METRICS</param>
<param name="accessType">READ_WRITE</param>
</interceptor-ref>

<result name="FORBIDDEN" type="json">
<param name="statusCode">403</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
<result name="SUCCESS" type="json">
<param name="root">trafficCollectorInfos</param>
</result>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>
<action name="api/fetchTrafficCollectorMetrics" class="com.akto.action.traffic_metrics.TrafficMetricsAction" method="fetchTrafficCollectorMetrics">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<interceptor-ref name="roleAccessInterceptor">
<param name="featureLabel">METRICS</param>
<param name="accessType">READ_WRITE</param>
</interceptor-ref>

<result name="FORBIDDEN" type="json">
<param name="statusCode">403</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
<result name="SUCCESS" type="json">
<param name="root">trafficCollectorMetrics</param>
</result>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

<action name="api/importDataFromPostmanFile" class="com.akto.action.PostmanAction" method="importDataFromPostmanFile">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,16 @@ function GraphMetric(props) {

const series = [
...dataForChart,
inputMetrics.length > 0 && inputMetrics.map((x, i) => {
return {
data: x.data,
color: '#FF4DCA',
name: x.name,
marker: {
enabled: false,
symbol: 'circle',
},
fillColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#000000'],
[1, '#000000'],
],
},
yAxis: i + 1,
};
}),
];

const chartOptions = {
chart: {
type,
zooming: {
type: 'x'
},
height: `${height}px`,
backgroundColor,
backgroundColor: backgroundColor || '#ffffff',
},
credits:{
enabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,47 @@ const settingRequests = {
data: {}
})
},
fetchRuntimeInstances(startTimestamp, endTimestamp) {
return request({
url: '/api/fetchRuntimeInstances',
method: 'post',
data: {
startTimestamp,
endTimestamp
}
})
},
fetchRuntimeMetrics(startTimestamp, endTimestamp, instanceId) {
return request({
url: '/api/fetchAllRuntimeMetrics',
method: 'post',
data: {
startTimestamp, endTimestamp,
instanceId
}
})
},
fetchTrafficMetrics(groupBy, startTimestamp, endTimestamp, names, host) {
return request({
url: '/api/fetchTrafficMetrics',
method: 'post',
data: {groupBy, startTimestamp, endTimestamp, names, host}
})
},
fetchTrafficCollectorInfos(startTimestamp, endTimestamp) {
return request({
url: '/api/fetchTrafficCollectorInfos',
method: 'post',
data: {startTimestamp, endTimestamp}
})
},
fetchTrafficCollectorMetrics(instanceId, startTimestamp, endTimestamp) {
return request({
url: '/api/fetchTrafficCollectorMetrics',
method: 'post',
data: {instanceId, startTimestamp, endTimestamp}
})
},

addCustomWebhook(webhookName, url, queryParams, method, headerString, body, frequencyInSeconds, selectedWebhookOptions, newEndpointCollections, newSensitiveEndpointCollections) {
return request({
Expand Down
Loading
Loading