This documentation and the Cisco Observability Platform functionalities it describes are subject to change. Data saved on the platform may disappear and APIs may change without notice.
Codex Use Cases
The following use cases are demonstrated using the Space Fleet reference solution.
Generate an Event Data from an Incoming Metric Data
You receive an input metric for the shield level of the Space fleet. If the shield level is less than 15% and above 5%, you must broadcast a Warning message over the intercom to the captain and other crews of the Space Fleet. If the shield level is below 5%, you must broadcast a Critical message. You can write a Codex workflow to generate the required events (Warning or Critical) from the metric (Shield level) and view the output event.
Input metric:
{
"entityMetadata": {
"type": {
"name": "torpedo",
"namespace": {
"name": "spacefleet",
"version": 1
}
},
"id": "bnswismwgvcduy"
},
"source": {
"name": "lca"
},
"partialAggregatePacketId": null,
"commonAttributes": null,
"tags": [{
"name": "aws.region",
"value": "us-west-1",
"valueList": null
}],
"type": {
"name": "shieldLevel",
"namespace": {
"name": "spacefleet",
"version": 1
}
},
"aggregationTemporality": "DELTA",
"isMonotonic": false,
"dataPoints": [{
"attributes": null,
"tags": null,
"timestamp": 585223000000000,
"granularitySecs": 60,
"value": {
"current": 5.34,
"groupCount": 2
}
}]
}
Codex workflow:
{
"entityMetadata": {
"type": {
"name": "torpedo",
"namespace": {
"name": "spacefleet",
"version": 1
}
},
"id": "bnswismwgvcduy"
},
"source": {
"name": "lca"
},
"partialAggregatePacketId": null,
"commonAttributes": null,
"tags": [{
"name": "aws.region",
"value": "us-west-1",
"valueList": null
}],
"type": {
"name": "shieldLevel",
"namespace": {
"name": "spacefleet",
"version": 1
}
},
"aggregationTemporality": "DELTA",
"isMonotonic": false,
"dataPoints": [{
"attributes": null,
"tags": null,
"timestamp": 585223000000000,
"granularitySecs": 60,
"value": {
"current": 5.34,
"groupCount": 2
}
}]
}
Codex workflow:
{
"id": "SpaceFleetShieldCriticalEventGenerator",
"version": "1.0",
"specVersion": "0.8",
"name": "SpaceFleetShieldCriticalEventGenerator",
"expressionLang": "Jsonata",
"description": "Generate shield critical event from the shield value metric",
"metadata": {
"solution": "spacefleet"
},
"start": "MetricReceived",
"functions": [
{
"name": "CreateEventFunction",
"type": "expression",
"operation": "($nonNullDoubleValues:=[$filter(metric.gauge.dataPoints,function($v,$i,$a){$v.asDouble!=null})];$nonNullIntValues:=[$filter(metric.gauge.dataPoints,function($v,$i,$a){$v.asInt!=null})];$intMin:=$sort($nonNullIntValues,function($l,$r){$l.asInt>$r.asInt})[0];$doubleMin:=$sort($nonNullDoubleValues,function($l,$r){$l.asDouble>$r.asDouble})[0];$findMin:=function($a,$b){$a.asInt<$b.asDouble?$a:$b};$minDataPoint:=$findMin($intMin,$doubleMin);$shield_level:=$minDataPoint.asDouble!=null?$minDataPoint.asDouble:$minDataPoint.asInt;$state:=$shield_level<25.0?\"CRITICAL\":\"WARNING\";$output:={\"entities\":metric.entities,\"timestamp\":$minDataPoint.timestamp,\"type\":\"spacefleet:shield_critical\",\"attributes\":{\"shield_level\":$shield_level,\"state\":$state}})"
}
],
"events": [
{
"name": "MetricReceived",
"type": "contracts:cloudevent/platform:metric.enriched.v1",
"source": "platform",
"kind": "consumed"
},
{
"name": "EventCreated",
"type": "contracts:cloudevent/platform:event.received.v1",
"source": "platform",
"kind": "produced"
}
],
"states": [
{
"name": "MetricReceived",
"type": "event",
"onEvents": [
{
"eventRefs": [
"MetricReceived"
],
"eventDataFilter": {
"data": "${ data }"
}
}
],
"transition": "MetricFilter"
},
{
"name": "MetricFilter",
"type": "switch",
"dataConditions": [
{
"condition": "type = \"spacefleet:shield_level\" and ($count(gauge.dataPoints[asDouble != null and asDouble < 50.0]) > 0 or $count(gauge.dataPoints[asInt != null and asInt < 50]) > 0)",
"transition": "GenerateEvent"
}
],
"defaultCondition": {
"end": true
}
},
{
"name": "GenerateEvent",
"type": "operation",
"actions": [
{
"functionRef": {
"refName": "CreateEventFunction",
"arguments": {
"metric": "${ $ }"
}
},
"actionDataFilter": {
"toStateData": "${ event }"
}
}
],
"end": {
"terminate": true,
"produceEvents": [
{
"eventRef": "EventCreated",
"data": "${ event }"
}
]
}
}
]
}
Output event:
{
"entityMetadata": {
"type": {
"name": "torpedo",
"namespace": {
"name": "spacefleet",
"version": 1
}
},
"id": "bnswismwgvcduy"
},
"source": {
"name": "lca"
},
"timestamp": 585223000000000,
"type": "spacefleet:shieldCritical",
"attributes": {
"shieldLevel": {
"value": 5.34
},
"state": {
"value": "WARNING"
}
}
}
Generate an Metric Data from an Incoming Event Data
You can use the news feed event from Space Fleet to compute a count metric for calculating the number of events received for a certain period. You use a feed type in the event as a dimension attribute to compute this metric.
Input event:
{
"data": {
"entityMetadata": {
"type": {
"name": "cluster",
"namespace": {
"name": "k8s",
"version": 1
}
},
"id": "tdgb9jrDNMSukH8ggAj46A"
},
"source": {
"name": "infra-agent"
},
"tags": [
{
"name": "cluster",
"value": "alerting-test-automation",
"valueList": null
},
{
"name": "cluster",
"value": "alerting-test-automation",
"valueList": null
}
],
"timestamp": 1669655280000000000,
"type": "spacefleet:newsfeed",
"attributes": {
"appd.isevent": {
"value": "true"
}
},
"raw": null,
"traceId": null,
"spanId": null
}
}
Codex workflow:
{
"id": "SpaceFleetNewsfeedCountMetricGenerator",
"version": "1.0",
"specVersion": "0.8",
"name": "SpaceFleetNewsfeedCountMetricGenerator",
"expressionLang": "Jsonata",
"description": "Generate newsfeed_count metric from the newsfeed event",
"metadata": {
"solution": "spacefleet"
},
"start": "EventReceived",
"functions": [
{
"name": "CreateMeasurementFunction",
"type": "expression",
"operation": "{\"entity\":entities[0],\"type\":\"spacefleet:newsfeed_count\",\"attributes\":attributes,\"measurements\":[{\"timestamp\":timestamp,\"intValue\":1}]}"
}
],
"events": [
{
"name": "EventEnriched",
"type": "contracts:cloudevent/platform:event.enriched.v1",
"source": "platform",
"kind": "consumed"
},
{
"name": "RawMeasurementCreated",
"type": "contracts:cloudevent/platform:measurement.received.v1",
"source": "platform",
"kind": "produced"
}
],
"states": [
{
"name": "EventReceived",
"type": "event",
"onEvents": [
{
"eventRefs": [
"EventEnriched"
],
"eventDataFilter": {
"data": "${ data }"
}
}
],
"transition": "EventFilter"
},
{
"name": "EventFilter",
"type": "switch",
"dataConditions": [
{
"condition": "type = \"spacefleet:newsfeed\"",
"transition": "GenerateMeasurement"
}
],
"defaultCondition": {
"end": true
}
},
{
"name": "GenerateMeasurement",
"type": "operation",
"actions": [
{
"functionRef": {
"refName": "CreateMeasurementFunction"
},
"actionDataFilter": {
"toStateData": "${ measurement }"
}
}
],
"end": {
"terminate": true,
"produceEvents": [
{
"eventRef": "RawMeasurementCreated",
"data": "${ measurement }"
}
]
}
}
]
}
<<<<<<< HEAD
=======
>>>>>>> 7a9046ba7ee07ae820d9c09e1493c9302f35198f
Output event:
{
"entityMetadata": {
"type": {
"name": "cluster",
"namespace": {
"name": "k8s",
"version": 1
}
},
"id": "tdgb9jrDNMSukH8ggAj46A"
},
"source": {
"name": "infra-agent"
},
"type": {
"name": "newsfeed_count",
"namespace": {
"name": "spacefleet",
"version": 1
}
},
"attributes": {
"appd.isevent": {
"value": "true"
}
},
"rawMeasurementValues": [
{
"timestamp": 1669655280000000000,
"value": 1
}
]
}