Updated on 2023-06-28 GMT+08:00

Modifying a Policy

Function

This API is used to modify a policy.

Alarm policies can be modified, but scheduled and periodic policies cannot.

URI

PUT /v1/{project_id}/pe/policy/{policy_id}

Table 1 describes the parameters.

Table 1 Parameters

Parameter

Mandatory

Description

project_id

Yes

Project ID.

policy_id

Yes

Policy ID.

Request

Request headers

Table 2 describes the request headers.

Table 2 Request headers

Parameter

Description

Mandatory

Example

Content-Type

Content type,

which is application/json;charset=utf-8.

Yes

application/json;charset=utf-8

Cluster-Id

Cluster ID.

Yes

-

Namespace

Namespace.

Yes

-

Deployment-Name

Application name.

Yes

-

Request parameters

Table 3 describes the request parameters.

Table 3 Request parameters

Parameter

Mandatory

Type

Value Range

Description

id

Yes

String

-

Policy ID.

name

Yes

String

The value must be 1 to 64 characters starting with a letter. Only digits, letters, underscores (_), and hyphens (-) are allowed.

Policy name, which cannot be modified.

policy_type

Yes

String

ALARM

Policy type. Currently, only ALARM policies are supported.

rule

Yes

See Table 4.

-

Policy trigger rule.

Table 4 rule parameters

Parameter

Mandatory

Type

Value Range

Description

conditions

Yes

See Table 5.

1–5

Condition contents. A rule can contain multiple conditions in AND relationships. One condition describes the matching method of one metric.

actions

Yes

See Table 6.

1–5

Action executed after a specified policy is successfully matched.

Table 5 conditions parameters

Parameter

Mandatory

Type

Value Range

Description

metric_namespace

Yes

String

  • PAAS.CONTAINER: application metric namespace.
  • PAAS.CUSTOMMETRICS: custom metric namespace.

Metric namespace.

metric_name

Yes

String

The value must be 1 to 255 characters long and meet the [a-zA-Z_:][a-zA-Z0-9_:]* expression. That is, the value must start with a letter, underscore (_), or colon (:). Only letters, digits, underscores, and colons are allowed.

Metric name.

metric_unit

Yes

String

-

Unit.

NOTE:

The value is retrieved from an AMS API and varies with the metric name.

period

Yes

Integer

20, 60, 300, 900, 1800, or 3600

Statistical period (unit: s).

evaluation_periods

Yes

Integer

1, 2, 3, 4, or 5

Number of consecutive periods.

statistic

Yes

String

Currently, only average is supported.

Statistic.

metric_operation

Yes

String

> and <.

For example, you can use > in a threshold criterion (when the value of a metric is greater than metric_thresholdUpdate) to trigger actions.

Metric operator.

metric_threshold

Yes

Float

[0, 2147483647]

Threshold criterion.

Table 6 actions parameters

Parameter

Mandatory

Type

Value Range

Description

type

Yes

String

  • scale_out_k8s
  • scale_out_vm
  • scale_in_k8s
  • scale_in_vm
  • scale_out_k8s and scale_out_vm indicate a scale-out.
  • scale_in_k8s and scale_in_vm indicate a scale-in.
NOTE:

The value containing k8s indicates a container application and that containing vm indicates a process application.

parameters

Yes

See Table 7.

-

Number of scale-in or -out instances.

Table 7 parameters

Parameter

Mandatory

Type

Value Range

Description

scale_unit

Yes

Integer

Minimum number of instances to the maximum number of instances in a policy group.

Number of scale-in or -out instances.

Example request

Example of an alarm policy

{   
    "id" : "5c2eecea-32ac-42c0-be30-f73b15d68429", 
    "name" : "policy_1", 
    "policy_type" : "ALARM", 
    "rule" : { 
        "conditions" : [{ 
                "metric_namespace" : "PAAS.CONTAINER", 
                "metric_name" : "cpuUsage", 
                "metric_unit" : "Percent", 
                "period" : 60, 
                "evaluation_periods" : 1, 
                "statistic" : "average", 
                "metric_operation" : ">", 
                "metric_threshold" : 70 
            } 
        ], 
        "actions" : [{ 
                "type" : "scale_out_k8s", 
                "parameters" : { 
                    "scale_unit" : 1 
                } 
            } 
        ] 
    } 
}

Response

Response parameters

Table 8 describes the response parameters.

Table 8 Response parameters

Parameter

Type

Description

errorCode

String

Error code.

errorMessage

String

Error details.

context

String

Details about a modified policy.

Example response

{
   "errorCode": 0,  
   "errorMessage": "",
   "context": { 
        "id" : "5c2eecea-32ac-42c0-be30-f73b15d68429", 
        "name" : "policy_1", 
        "policy_type" : "ALARM", 
        "rule" : { 
            "conditions" : [{ 
                    "metric_namespace" : "PAAS.CONTAINER", 
                    "metric_name" : "cpuUsage", 
                    "metric_unit" : "Percent", 
                    "period" : 60, 
                    "evaluation_periods" : 1, 
                    "statistic" : "average", 
                    "metric_operation" : ">", 
                    "metric_threshold" : 70 
                } 
            ], 
            "actions" : [{ 
                    "type" : "scale_out_k8s", 
                    "parameters" : { 
                        "scale_unit" : 1 
                    }   
                } 
            ] 
        } 
    } 
}

Error Code

Table 9 Error codes

Error Code

Message

Solution

SVCSTG.PE.4001101

Invalid parameter.

Check whether the parameter meets requirements.

SVCSTG.PE.4031012

Failed to verify the project ID.

Check whether the parameter meets requirements.

SVCSTG.PE.4033008

Failed to update the scheduled or periodic policy.

Check whether the parameter meets requirements.

SVCSTG.PE.5001201

Failed to insert or update data in the background.

Contact technical support.

SVCSTG.PE.5001203

Query error.

Contact technical support.

SVCSTG.PE.5003007

Failed to update the threshold rule.

Contact technical support.