Updated on 2022-06-01 GMT+08:00

Modifying a Policy

Function

This API is used to modify a policy. [It is not supported in versions later than 1.8.0.] (tag:hcs) Alarm policies can be modified, but scheduled and periodic policies cannot.

URI

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

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID

policy_id

Yes

String

Policy ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

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

Enumeration values:

  • application/json;charset=utf-8

  • application/json

Cluster-Id

Yes

String

Cluster ID.

Namespace

Yes

String

Namespace.

Deployment-Name

Yes

String

Application name.

X-Auth-Token

Yes

String

Project-level token obtained from IAM.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

id

Yes

String

Policy ID.

name

Yes

String

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

policy_type

Yes

String

Policy type. Currently, only ALARM policies are supported.

Enumeration values:

  • ALARM

rule

Yes

AlarmRule object

Policy trigger rule.

group_id

Yes

String

Policy group ID.

Table 4 AlarmRule

Parameter

Mandatory

Type

Description

actions

Yes

Array of Action objects

Action executed after a specified policy is matched.

conditions

Yes

Array of AlarmConditions objects

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

Table 5 Action

Parameter

Mandatory

Type

Description

type

Yes

String

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 scale-in or -out for containerized applications and that containing vm indicates a scale-in or -out for process applications.

Enumeration values:

  • scale_out_k8s

  • scale_out_vm

  • scale_in_k8s

  • scale_in_vm

parameters

Yes

Array of Parameter objects

Number of scale-in or -out instances.

Table 6 Parameter

Parameter

Mandatory

Type

Description

scale_unit

Yes

Integer

Number of scale-in or -out instances. The value is between the minimum number of instances to the maximum number of instances in a policy group.

Table 7 AlarmConditions

Parameter

Mandatory

Type

Description

metric_namespace

Yes

String

Metric namespace.

Enumeration values:

  • PAAS.CONTAINER

  • PAAS.CUSTOMMETRICS

metric_name

Yes

String

Metric name.

Enumeration values:

  • ^[a-zA-Z_:][a-zA-Z0-9_:]{0

  • 254}$

metric_unit

Yes

String

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

period

Yes

Integer

Statistical period (unit: s).

Enumeration values:

  • 20

  • 60

  • 300

  • 900

  • 1800

  • 3600

evaluation_periods

Yes

Integer

Number of consecutive periods.

Enumeration values:

  • 1

  • 2

  • 3

  • 4

  • 5

statistic

Yes

String

Statistic.

Enumeration values:

  • average

metric_operation

Yes

String

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

Enumeration values:

  • >

  • <

metric_threshold

Yes

Integer

Threshold condition.

Response Parameters

Status code: 200

Table 8 Response body parameters

Parameter

Type

Description

errorCode

String

Error code.

errorMessage

String

Details.

context

PePolicyContext object

Details about a modified policy.

Table 9 PePolicyContext

Parameter

Type

Description

id

String

Policy ID.

name

String

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

policy_type

String

Policy type. Currently, only ALARM policies are supported.

Enumeration values:

  • ALARM

rule

AlarmRule object

Policy trigger rule.

Table 10 AlarmRule

Parameter

Type

Description

actions

Array of Action objects

Action executed after a specified policy is matched.

conditions

Array of AlarmConditions objects

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

Table 11 Action

Parameter

Type

Description

type

String

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 scale-in or -out for containerized applications and that containing vm indicates a scale-in or -out for process applications.

Enumeration values:

  • scale_out_k8s

  • scale_out_vm

  • scale_in_k8s

  • scale_in_vm

parameters

Array of Parameter objects

Number of scale-in or -out instances.

Table 12 Parameter

Parameter

Type

Description

scale_unit

Integer

Number of scale-in or -out instances. The value is between the minimum number of instances to the maximum number of instances in a policy group.

Table 13 AlarmConditions

Parameter

Type

Description

metric_namespace

String

Metric namespace.

Enumeration values:

  • PAAS.CONTAINER

  • PAAS.CUSTOMMETRICS

metric_name

String

Metric name.

Enumeration values:

  • ^[a-zA-Z_:][a-zA-Z0-9_:]{0

  • 254}$

metric_unit

String

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

period

Integer

Statistical period (unit: s).

Enumeration values:

  • 20

  • 60

  • 300

  • 900

  • 1800

  • 3600

evaluation_periods

Integer

Number of consecutive periods.

Enumeration values:

  • 1

  • 2

  • 3

  • 4

  • 5

statistic

String

Statistic.

Enumeration values:

  • average

metric_operation

String

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

Enumeration values:

  • >

  • <

metric_threshold

Integer

Threshold condition.

Example Requests

Modify an alarm policy.

PUT https://{Endpoint}/v1/{project_id}/pe/policy/{policy_id}

{
  "group_id" : "943eba0f-b10a-4066-6261-1857a53500ff",
  "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
      }
    } ]
  }
}

Example Responses

Status code: 200

OK: The request is successful.

{
  "errorCode" : "SVCSTG.PE.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
        }
      } ]
    }
  }
}

Status Codes

Status Code

Description

200

OK: The request is successful.

400

Bad Request: Invalid request. The client should not repeat the request without modifications.

401

Unauthorized: The authorization information is incorrect or invalid.

403

Forbidden: The request is rejected. The server has received the request and understood it, but the server refuses to respond to it. The client should not repeat the request without modifications.

500

Internal Server Error: The server is able to receive the request but unable to understand the request.

503

Service Unavailable: The requested service is invalid. The client should not repeat the request without modifications.

Error Codes

See Error Codes.