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 display runtime metrics #1424

Open
wants to merge 13 commits into
base: feature/mini-runtime-release
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
9 changes: 2 additions & 7 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ jobs:
docker buildx create --use
# Build a docker container and push it to DockerHub
cd apps/mini-runtime
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/$REGISTRY_ALIAS/akto-api-security-mini-runtime:$IMAGE_TAG -t $ECR_REGISTRY/$REGISTRY_ALIAS/akto-api-security-mini-runtime:$IMAGE_TAG1 -t $ECR_REGISTRY/$REGISTRY_ALIAS/akto-api-security-mini-runtime:$IMAGE_TAG2 -t $ECR_REGISTRY/$REGISTRY_ALIAS/akto-api-security-mini-runtime:$IMAGE_TAG3 . --push
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/$REGISTRY_ALIAS/akto-api-security-mini-runtime:$IMAGE_TAG . --push
echo "::set-output name=image::$ECR_REGISTRY/akto-api-security-mini-runtime:$IMAGE_TAG"
cd ../mini-testing
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/$REGISTRY_ALIAS/akto-api-security-mini-testing:$IMAGE_TAG3 . --push
echo "::set-output name=image::$ECR_REGISTRY/akto-api-security-mini-testing:$IMAGE_TAG3"

- name: DockerHub login
env:
Expand All @@ -92,6 +89,4 @@ jobs:
docker buildx create --use
# Build a docker container and push it to DockerHub
cd apps/mini-runtime
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/mini-runtime:$IMAGE_TAG -t $ECR_REGISTRY/mini-runtime:$IMAGE_TAG1 -t $ECR_REGISTRY/mini-runtime:$IMAGE_TAG2 -t $ECR_REGISTRY/mini-runtime:$IMAGE_TAG3 . --push
cd ../mini-testing
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/mini-testing:$IMAGE_TAG3 . --push
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/mini-runtime:$IMAGE_TAG . --push
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.akto.action.traffic_metrics;

import com.akto.action.UserAction;
import com.akto.dao.traffic_metrics.RuntimeMetricsDao;
import com.akto.dao.traffic_metrics.TrafficMetricsDao;
import com.akto.dto.traffic_metrics.RuntimeMetrics;
import com.akto.dto.traffic_metrics.TrafficMetrics;
import com.mongodb.BasicDBObject;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Accumulators;
import com.mongodb.client.model.Aggregates;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.Sorts;

import org.bson.Document;
import org.bson.conversions.Bson;

Expand All @@ -16,11 +21,16 @@
public class TrafficMetricsAction extends UserAction {
private int startTimestamp;
private int endTimestamp;
private String instanceId;


private List<TrafficMetrics.Name> names;
private String groupBy;
private String host;
private int vxlanID;
List<RuntimeMetrics> runtimeMetrics;
List<String> instanceIds;


public static final String ID = "_id.";

Expand Down Expand Up @@ -113,6 +123,48 @@ public String execute() {
return SUCCESS.toUpperCase();
}

public String fetchRuntimeInstances() {
instanceIds = new ArrayList<>();
Bson filters = RuntimeMetricsDao.buildFilters(startTimestamp, endTimestamp);
runtimeMetrics = RuntimeMetricsDao.instance.findAll(filters, 0, 0, Sorts.descending("timestamp"));
for (RuntimeMetrics metric: runtimeMetrics) {
instanceIds.add(metric.getInstanceId());
}

return SUCCESS.toUpperCase();
}

public String fetchRuntimeMetrics() {
Bson filters = RuntimeMetricsDao.buildFilters(startTimestamp, endTimestamp, instanceId);
// runtimeMetrics = RuntimeMetricsDao.instance.findAll(filters, 0, 0, Sorts.descending("timestamp"));
runtimeMetrics = new ArrayList<>();

try (MongoCursor<BasicDBObject> cursor = RuntimeMetricsDao.instance.getMCollection().aggregate(
Arrays.asList(
Aggregates.match(filters),
Aggregates.sort(Sorts.descending("timestamp")),
Aggregates.group(new BasicDBObject("name", "$name"), Accumulators.first("latestDoc", "$$ROOT"))
), BasicDBObject.class
).cursor()) {
while (cursor.hasNext()) {
BasicDBObject basicDBObject = cursor.next();
BasicDBObject latestDoc = (BasicDBObject) basicDBObject.get("latestDoc");
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();
Expand Down Expand Up @@ -150,4 +202,29 @@ public void setHost(String host) {
public void setVxlanID(int vxlanID) {
this.vxlanID = vxlanID;
}

public List<RuntimeMetrics> getRuntimeMetrics() {
return runtimeMetrics;
}

public void setRuntimeMetrics(List<RuntimeMetrics> runtimeMetrics) {
this.runtimeMetrics = runtimeMetrics;
}

public List<String> getInstanceIds() {
return instanceIds;
}

public void setInstanceIds(List<String> instanceIds) {
this.instanceIds = instanceIds;
}

public String getInstanceId() {
return instanceId;
}

public void setInstanceId(String instanceId) {
this.instanceId = instanceId;
}

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

<action name="api/fetchRuntimeInstances" class="com.akto.action.traffic_metrics.TrafficMetricsAction" method="fetchRuntimeInstances">
<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/fetchRuntimeMetrics" class="com.akto.action.traffic_metrics.TrafficMetricsAction" method="fetchRuntimeMetrics">
<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/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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,15 @@ 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,
};
}),
...dataForChart
];

const chartOptions = {
chart: {
type,
zooming: {
type: 'x'
},
height: `${height}px`,
backgroundColor,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ 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',
Expand Down
Loading
Loading