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

[NEW] AOM #540

Draft
wants to merge 12 commits into
base: devel
Choose a base branch
from
Draft
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
141 changes: 141 additions & 0 deletions openstack/aom/v2/log/ListLogItems.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package log

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type ListLogItemsOpts struct {
// Log type:
//
// app_log: application log
//
// node_log: host log
//
// custom_log: log in a custom path
Category string `json:"category" required:"true"`
// Log filter criteria, which vary according to log sources.
SearchKey SearchKey `json:"searchKey" required:"true"`
// Cloud Container Engine (CCE) cluster ID.
ClusterId string `json:"clusterId" required:"true"`
// CCE cluster namespace.
NameSpace string `json:"nameSpace,omitempty"`
// Service name.
AppName string `json:"appName,omitempty"`
// Container pod name.
PodName string `json:"podName,omitempty"`
// Log file name.
PathFile string `json:"pathFile,omitempty"`
// IP address of the VM where logs are located.
HostIP string `json:"hostIP,omitempty"`
// Enter a keyword between two adjacent delimiters for exact search.
//
// Enter a keyword for fuzzy search. Example: RROR, ERRO?, *ROR*, ERR*, or ER*OR.
//
// Enter a phrase for exact search. Example: Start to refresh alm Statistic.
//
// Enter contents containing AND (&&) or OR (||) for search. Example: query&&logs or query||logs.
//
// Default delimiters:
//
// , '";=()[]{}@&<>/:\n\t\r
KeyWord string `json:"keyWord,omitempty"`
// Start time of the query (UTC, in ms).
StartTime *int64 `json:"startTime" required:"true"`
// End time of the query (UTC, in ms).
EndTime *int64 `json:"endTime" required:"true"`
// Whether to hide the system log (icagent\kubectl) during the query. 0 (default): Hide. 1: Not hide.
//
// Value Range
//
// 0 or 1
HideSyslog *int `json:"hideSyslog,omitempty"`
}

type SearchKey struct {
// CCE cluster ID.
ClusterId string `json:"clusterId" required:"true"`
// CCE cluster namespace.
NameSpace string `json:"nameSpace,omitempty"`
// Application name.
AppName string `json:"appName,omitempty"`
// Container instance name.
PodName string `json:"podName,omitempty"`
// Log file name.
PathFile string `json:"pathFile,omitempty"`
// IP address of the VM where logs are located.
HostIP string `json:"hostIP,omitempty"`
}

func ListLogItems(client *golangsdk.ServiceClient, opts ListLogItemsOpts) (*ListLogItemsResponse, error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}

// POST /v2/{project_id}/als/action
raw, err := client.Post(client.ServiceURL("als", "action")+"?type=querylogs", b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res ListLogItemsResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListLogItemsResponse struct {
// Response code. Example: AOM.0200, which indicates a success response.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// Metadata, including total number of returned records and results.
Result ItemsResult `json:"result"`
}

type ItemsResult struct {
// Number of returned records.
Total *int `json:"total"`
// Data array.
Data []ItemData `json:"data"`
}

type ItemData struct {
// Log type.
Category string `json:"category"`
// Hash value of the log source.
LogHash string `json:"loghash"`
// Cloud Container Engine (CCE) cluster ID.
ClusterId string `json:"clusterId"`
// CCE cluster name.
ClusterName string `json:"clusterName"`
// CCE cluster namespace.
NameSpace string `json:"nameSpace"`
// CCE container pod name.
PodName string `json:"podName"`
// Service name.
AppName string `json:"appName"`
// Service ID of an AOM resource.
ServiceID string `json:"serviceID"`
// CCE container name.
ContainerName string `json:"containerName"`
// Source log data.
LogContent string `json:"logContent"`
// Absolute path of a log file.
PathFile string `json:"pathFile"`
// IP address of the VM where log files are located.
HostIP string `json:"hostIP"`
// ID of a host in a cluster.
HostId string `json:"hostId"`
// Name of the VM where log files are located.
HostName string `json:"hostName"`
// Log collection time (UTC time, in ms).
CollectTime string `json:"collectTime"`
// Sequence number of a log line.
LineNum string `json:"lineNum"`
// Size of a single-line log.
LogContentSize string `json:"logContentSize"`
}
35 changes: 35 additions & 0 deletions openstack/aom/v2/monitor/AddAlarmRule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package monitor

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

func AddAlarmRule(client *golangsdk.ServiceClient, opts Threshold) (*AddAlarmRuleResponse, error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}

// POST /v2/{project_id}/ams/alarms
raw, err := client.Post(client.ServiceURL("ams", "alarms"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res AddAlarmRuleResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type AddAlarmRuleResponse struct {
// Response code.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// Threshold rule code.
AlarmId *int64 `json:"alarmId"`
}
86 changes: 86 additions & 0 deletions openstack/aom/v2/monitor/AddMetricData.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package monitor

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type AddMetricDataOpts struct {
// Metric data.
Metric MetricAdd `json:"metric" required:"true"`
//
Values []Value `json:"values" required:"true"`
// Data collection time, which must meet the following requirement:
//
// Current UTC time - Data collection time <= 24 hours, or Data collection time - Current UTC time <= 30 minutes
//
// Value Range
//
// UNIX timestamp, in ms.
CollectTime *int64 `json:"collect_time" required:"true"`
}

type MetricAdd struct {
// Metric namespace.
//
// Value Range
//
// Namespace, which must be in the format of service.item. The value must be 3 to 32 characters starting with a letter. Only letters, digits, and underscores (_) are allowed. In addition, service cannot start with PAAS or SYS.
Namespace string `json:"namespace" required:"true"`
// List of metric dimensions.
//
// Value Range
//
// Each dimension is a JSON object, and its structure is as follows:
//
// dimension.name: 1-32 characters.
//
// dimension.value: 1-64 characters.
Dimensions []Dimension `json:"dimensions" required:"true"`
}

type Value struct {
// Data unit.
Unit string `json:"unit,omitempty"`
// Metric name.
MetricName string `json:"metric_name" required:"true"`
// Data type.
//
// Value Range
//
// "int" or "float"
Type string `json:"type,omitempty"`
// Metric value.
//
// Value Range
//
// Valid numeral type.
Value *float32 `json:"value" required:"true"`
}

func AddMetricData(client *golangsdk.ServiceClient, opts AddMetricDataOpts) (*AddMetricDataResponse, error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}

// POST /v2/{project_id}/ams/report/metricdata
raw, err := client.Post(client.ServiceURL("ams", "report", "metricdata"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res AddMetricDataResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type AddMetricDataResponse struct {
// Response code.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
}
13 changes: 13 additions & 0 deletions openstack/aom/v2/monitor/DeleteAlarmRule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package monitor

import (
"strconv"

"github.com/opentelekomcloud/gophertelekomcloud"
)

func DeleteAlarmRule(client *golangsdk.ServiceClient, alarmId int64) (err error) {
// DELETE /v2/{project_id}/ams/alarms/{alarm_id}
_, err = client.Delete(client.ServiceURL("ams", "alarms", strconv.FormatInt(alarmId, 10)), nil)
return
}
60 changes: 60 additions & 0 deletions openstack/aom/v2/monitor/ListAlarmRule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package monitor

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type ListAlarmRuleOpts struct {
// Value range: 1-1000. Default value: 1000.
//
// Maximum number of returned records.
//
// Value Range
//
// (0,1000]
Limit *int `q:"limit"`
// Pagination information.
//
// Value Range
//
// [0, (Maximum value of the int type - 1000)]
Start *int `q:"start"`
}

func ListAlarmRule(client *golangsdk.ServiceClient, opts ListAlarmRuleOpts) (*ListAlarmRuleResponse, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return nil, err
}

// GET /v2/{project_id}/ams/alarms
raw, err := client.Get(client.ServiceURL("ams", "alarms")+q.String(), nil, nil)
if err != nil {
return nil, err
}

var res ListAlarmRuleResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListAlarmRuleResponse struct {
// Response code.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// Metadata, including pagination information.
MetaData MetaData `json:"metaData"`
// Threshold rule list.
Thresholds []Threshold `json:"thresholds"`
}

type MetaData struct {
// Number of returned records.
Count *int `json:"count"`
// Total number of records.
Start string `json:"start"`
// Start of the next page, which is used for pagination.
Total *int `json:"total"`
}
96 changes: 96 additions & 0 deletions openstack/aom/v2/monitor/ListMetricItems.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package monitor

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type ListMetricItemsQuery struct {
// Metric query mode. The information carried by metricItems in the request body is used to query metrics.
Type string `q:"type"`
// Maximum number of returned records. Value range: 1-1000. Default value: 1000.
Limit int `q:"limit"`
// Start position of a pagination query. The value is a non-negative integer.
Start int `q:"start"`
}

type ListMetricItemsOpts struct {
// Metric namespace.
//
// PAAS.CONTAINER: application metric.
//
// PAAS.NODE: node metric.
//
// PAAS.SLA: Service Level Agreement (SLA) metric.
//
// PAAS.AGGR: cluster metric.
//
// CUSTOMMETRICS: custom metric.
//
// Value Range
//
// PAAS.CONTAINER, PAAS.NODE, PAAS.SLA, PAAS.AGGR, CUSTOMMETRICS, and so on.
Namespace string `json:"namespace" required:"true"`
// Metric dimension.
//
// dimensions.name: dimension name, such as clusterName, clusterId, appName, appID, deploymentName, podName, podID, containerName, or containerID.
//
// dimensions.value: dimension value, such as a specific application instance ID.
Dimensions []Dimension `json:"dimensions,omitempty"`
// Metric name.
//
// Value Range
//
// 1-1000 characters.
MetricName string `json:"metricName,omitempty"`
}

type Dimension struct {
Name string `json:"name" required:"true"`
Value string `json:"value" required:"true"`
}

func ListMetricItems(client *golangsdk.ServiceClient, opts []ListMetricItemsOpts, query ListMetricItemsQuery) (*ListMetricItemsResponse, error) {
q, err := golangsdk.BuildQueryString(query)
if err != nil {
return nil, err
}

b, err := build.RequestBody(opts, "metricItems")
if err != nil {
return nil, err
}

// POST /v2/{project_id}/ams/metrics
raw, err := client.Post(client.ServiceURL("ams", "metrics")+q.String(), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res ListMetricItemsResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListMetricItemsResponse struct {
// Response code. Example: AOM.0200, which indicates a success response.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// List of metrics.
Metrics []Metric `json:"metrics"`
}

type Metric struct {
// Namespace.
Namespace string `json:"namespace"`
// Metric name.
MetricName string `json:"metricName"`
// Metric unit.
Unit string `json:"unit"`
// List of metric dimensions.
Dimensions []Dimension `json:"dimensions"`
}
136 changes: 136 additions & 0 deletions openstack/aom/v2/monitor/ShowAlarmRule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package monitor

import (
"strconv"

"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

func ShowAlarmRule(client *golangsdk.ServiceClient, alarmId int64) (*ShowAlarmRuleResponse, error) {
// GET /v2/{project_id}/ams/alarms/{alarm_id}
raw, err := client.Get(client.ServiceURL("ams", "alarms", strconv.FormatInt(alarmId, 10)), nil, nil)
if err != nil {
return nil, err
}

var res ShowAlarmRuleResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ShowAlarmRuleResponse struct {
// Response code.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// Threshold rule list.
Thresholds []Threshold `json:"thresholds"`
}

type Threshold struct {
// Statistic.
//
// Value Range
//
// maximum, minimum, average, sum, or sampleCount.
Statistic string `json:"statistic" required:"true"`
// Namespace.
//
// Value Range
//
// 1-255 characters. Colons (:) are not allowed.
Namespace string `json:"namespace" required:"true"`
// Metric name.
//
// Value Range
//
// 1-255 characters.
MetricName string `json:"metricName" required:"true"`
// Statistical period.
//
// Value Range
//
// 20000, 60000, 300000, 900000, 1800000, 3600000, 14400000, or 86400000
Period *int `json:"period" required:"true"`
// Alarm severity.
//
// Value Range
//
// 4, 3, 2, or 1
AlarmLevel *int `json:"alarmLevel,omitempty"`
// Number of consecutive periods.
//
// Value Range
//
// 4, 3, or 2
EvaluationPeriods *int `json:"evaluationPeriods" required:"true"`
// Comparison operator.
//
// Value Range
//
// >, >=, <, or <=
ComparisonOperator string `json:"comparisonOperator" required:"true"`
// Threshold.
//
// Value Range
//
// Non-null value that can be converted to a value of the double type. Once converted, the value cannot be null, or be a positive or negative infinity.
Threshold *int64 `json:"threshold" required:"true"`
// Threshold name.
//
// Value Range
//
// 1-255 characters. Special characters are not allowed.
AlarmName string `json:"alarmName" required:"true"`
// Metric dimension.
//
// Value Range
//
// Non-null; number of dimensions < 100
Dimensions []Dimension `json:"dimensions" required:"true"`
// Metric unit.
//
// Value Range
//
// Number of characters < 32
Unit string `json:"unit,omitempty"`
// Whether to enable the alarm function.
ActionEnabled *bool `json:"actionEnabled,omitempty"`
// Alarm action.
//
// Value Range
//
// Size <= 5
AlarmActions []string `json:"alarmActions,omitempty"`
// Suggestion.
//
// Value Range
//
// Number of characters < 255
AlarmAdvice string `json:"alarmAdvice,omitempty"`
// Threshold rule description.
//
// Value Range
//
// Number of characters < 255
AlarmDescription string `json:"alarmDescription,omitempty"`
// Action to be taken when data is insufficient.
//
// Value Range
//
// Size <= 5
InsufficientDataActions []string `json:"insufficientDataActions,omitempty"`
// Recovery action.
//
// Value Range
//
// Size <= 5
OkActions []string `json:"okActions,omitempty"`
// ?
StateValue string `json:"stateValue,omitempty"`
// ?
StateReason string `json:"stateReason,omitempty"`
// ?
StateUpdatedTimestamp *int64 `json:"stateUpdatedTimestamp,omitempty"`
}
140 changes: 140 additions & 0 deletions openstack/aom/v2/monitor/ShowMetricsData.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package monitor

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type ShowMetricsDataQuery struct {
// Filled value for breakpoints in monitoring data. Default value: -1.
//
// -1: Breakpoints are filled with -1.
//
// 0: Breakpoints are filled with 0.
//
// null: Breakpoints are filled with null.
//
// average: Breakpoints are filled with the average value of adjacent valid data. If there is no valid data, breakpoints are filled with null.
FillValue string `q:"fillValue"`
}

type ShowMetricsDataOpts struct {
// List of metrics.
//
// Value Range
//
// A maximum of 20 metrics are supported.
Metrics []MetricQuery `json:"metrics" required:"true"`
// Data monitoring granularity.
//
// Value Range
//
// Enumerated value. Options:
//
// 60: The data monitoring granularity is 1 minute.
//
// 300: The data monitoring granularity is 5 minutes.
//
// 900: The data monitoring granularity is 15 minutes.
//
// 3600: The data monitoring granularity is 1 hour.
Period *int `json:"period" required:"true"`
// Query time period. For example, -1.-1.5 indicates the last 5 minutes. 1501545600000.1501632000000.1440 indicates the fixed time period from 08:00:00 on August 1, 2017 to 08:00:00 on August 2, 2017.
//
// Time range/Period <= 1440
//
// The timerange and period must use the same unit.
//
// Value Range
//
// Format: start time (UTC, in ms).end time (UTC, in ms).number of minutes in the time period. When the start time and end time are -1, it indicates the latest N minutes. N indicates the time period by the granularity of minute.
Timerange string `json:"timerange" required:"true"`
// Statistic.
//
// Value Range
//
// maximum, minimum, sum, average, or sampleCount.
Statistics []string `json:"statistics" required:"true"`
}

type MetricQuery struct {
// Metric namespace.
//
// Value Range
//
// PAAS.CONTAINER, PAAS.NODE, PAAS.SLA, PAAS.AGGR, and CUSTOMMETRICS.
Namespace string `json:"namespace" required:"true"`
// Metric name.
//
// Value Range
//
// 1-255 characters.
MetricName string `json:"metricName" required:"true"`
// Metric dimension.
//
// dimensions.name: dimension name. Example: appName.
//
// dimensions.value: dimension value, such as a specific application name.
//
// Value Range
//
// Neither the array nor the name/value of any dimension in the array can be left blank.
Dimensions []Dimension `json:"dimensions" required:"true"`
}

func ShowMetricsData(client *golangsdk.ServiceClient, opts ShowMetricsDataOpts, query ShowMetricsDataQuery) (*ShowMetricsDataResponse, error) {
q, err := golangsdk.BuildQueryString(query)
if err != nil {
return nil, err
}

b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}

// POST /v2/{project_id}/ams/metricdata
raw, err := client.Post(client.ServiceURL("ams", "metricdata")+q.String(), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res ShowMetricsDataResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ShowMetricsDataResponse struct {
// Response code.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// Metric list.
Metrics []Metrics `json:"metrics"`
}

type Metrics struct {
// Query parameters.
Metric Metric `json:"metric"`
// Key metric.
DataPoints []DataPoint `json:"dataPoints"`
}

type DataPoint struct {
// Timestamp
Timestamp int64 `json:"timestamp"`
// Time series unit.
Unit string `json:"unit"`
// Statistic.
Statistics []Statistic `json:"statistics"`
}

type Statistic struct {
// Statistic.
Statistic string `json:"statistic"`
// Statistical result.
Value float64 `json:"value"`
}
35 changes: 35 additions & 0 deletions openstack/aom/v2/monitor/UpdateAlarmRule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package monitor

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

func UpdateAlarmRule(client *golangsdk.ServiceClient, opts Threshold) (*UpdateAlarmRuleResponse, error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}

// PUT /v2/{project_id}/ams/alarms
raw, err := client.Put(client.ServiceURL("ams", "alarms"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res UpdateAlarmRuleResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type UpdateAlarmRuleResponse struct {
// Response code.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// Threshold rule code.
AlarmId *int64 `json:"alarmId"`
}