Skip to content

Latest commit

 

History

History
156 lines (135 loc) · 5.23 KB

File metadata and controls

156 lines (135 loc) · 5.23 KB
description
This page provides the technical details of the Assign Metrics policy

Assign Metrics

{% hint style="warning" %} This feature requires Gravitee's Enterprise Edition. {% endhint %}

Overview

You can use the assign-metrics policy to push extra metrics in addition to the natively provided request metrics.

These metrics can then be used from analytics dashboards to create custom widgets and, optionally, apply aggregations based on their value.

Functional and implementation information for the assign-metrics policy is organized into the following sections:

Examples

{% hint style="warning" %} This policy can be applied to v2 APIs, v4 HTTP proxy APIs, and v4 message APIs. It cannot be applied to v4 TCP proxy APIs. {% endhint %}

{% tabs %} {% tab title="HTTP proxy API example" %} To display your request distribution based on a particular HTTP header in your dashboards, create the custom metric shown below:

"assign-metrics": {
    "metrics": [
        {
            "name": "myCustomHeader,
            "value": "{#request.headers['X-MyCustomHeader'] != null ? #request.headers['X-MyCustomHeader'][0] : null}"
        }
    ]
}

{% endtab %}

{% tab title="Message API example" %} An example of this policy applied at the message level is shown below:

{
    "id": "subscribe-assign-metrics",
    "name": "subscribe-assign-metrics",
    "apiVersion": "1.0",
    "definitionVersion": "4.0.0",
    "type": "message",
    "analytics": {},
    "description": "subscribe-assign-metrics",
    "listeners": [
        {
            "type": "http",
            "paths": [
                {
                    "path": "/subscribe-assign-metrics"
                }
            ],
            "entrypoints": [
                {
                    "type": "sse",
                    "configuration": {
                        "heartbeatIntervalInMs": 5000,
                        "metadataAsComment": false,
                        "headersAsComment": true
                    }
                }
            ]
        }
    ],
    "endpointGroups": [
        {
            "name": "default",
            "type": "mock",
            "endpoints": [
                {
                    "name": "default",
                    "type": "mock",
                    "weight": 1,
                    "inheritConfiguration": false,
                    "configuration": {
                        "messageInterval": 500,
                        "messageContent": "custom-metric",
                        "messageCount": 12
                    }
                }
            ]
        }
    ],
    "flows": [
        {
            "name": "test-flow",
            "enabled": true,
            "selectors": [
                {
                    "type": "channel",
                    "operation": ["SUBSCRIBE"],
                    "channel": "/",
                    "channel-operator": "STARTS_WITH"
                }
            ],
            "request": [],
            "response": [],
            "subscribe": [
                {
                    "name": "Assign metrics",
                    "description": "",
                    "enabled": true,
                    "policy": "policy-assign-metrics",
                    "configuration": {
                        "metrics": [
                            {
                                "name": "content",
                                "value": "{#message.content}"
                            },
                            {
                                "name": "recordable",
                                "value": "{#message.attributes['message.recordable']}"
                            },
                            {
                                "name": "static",
                                "value": "value"
                            }
                        ]
                    }
                }
            ],
            "publish": []
        }
    ]
}

{% endtab %} {% endtabs %}

Configuration

You can enable or disable the policy with policy identifier policy-assign-metrics.

Phases

The phases checked below are supported by the assign-metrics policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequesttrue
onResponsetrueonResponsetrue
onRequestContenttrueonMessageRequesttrue
onResponseContenttrueonMessageResponsetrue

Compatibility matrix

The following is the compatibility matrix for APIM and the assign-metrics policy:

Plugin VersionSupported APIM versions
1.xUp to 3.1.7
2.x3.18 to 3.20
3.x4.0+