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

Add support for Event Orchestration External Data Cache Variables #159

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions pagerduty/event_orchestration_cache_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ type EventOrchestrationCacheVariableCondition struct {
// Configuration for a cache variable changes depending on the type:
// - if `Type` is `recent_value`; then use `Regex` and `Source`
// - if `Type` is `trigger_event_count`; then use `TTLSeconds`
// - if `Type` is `external_data`; then use `DataType` and `TTLSeconds`
type EventOrchestrationCacheVariableConfiguration struct {
Type string `json:"type,omitempty"`
Regex string `json:"regex,omitempty"`
Source string `json:"source,omitempty"`
DataType string `json:"data_type,omitempty"`
TTLSeconds int `json:"ttl_seconds,omitempty"`
}

Expand All @@ -28,6 +30,7 @@ type EventOrchestrationCacheVariable struct {
Disabled bool `json:"disabled"`
Conditions []*EventOrchestrationCacheVariableCondition `json:"conditions"`
Configuration *EventOrchestrationCacheVariableConfiguration `json:"configuration,omitempty"`
DataEndpoint string `json:"data_endpoint,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
CreatedBy *UserReference `json:"created_by,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
Expand Down
114 changes: 101 additions & 13 deletions pagerduty/event_orchestration_cache_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,31 @@ func TestGlobalEventOrchestrationCacheVariableList(t *testing.T) {
"self": "https://api.pagerduty.com/users/P8B9WR8",
"type": "user_reference"
}
},
{
"id": "fffd20a2-8240-4df3-b996-964968464a3f",
"name": "example_3",
"configuration": {
"type": "external_data",
"data_type": "boolean",
"ttl_seconds": 1200
},
"created_at": "2025-02-07T18:50:58Z",
"created_by": {
"id": "P24PCRC",
"self": "https://api.pagerduty.com/users/P24PCRC",
"type": "user_reference"
},
"data_endpoint": "https://api.pagerduty.com/event_orchestrations/a64f9c87-6adc-4f89-a64c-2fdd8cba4639/cache_variables/fffd20a2-8240-4df3-b996-964968464a3f/data",
"updated_at": "2025-02-07T20:00:43Z",
"updated_by": {
"id": "P23PCRC",
"self": "https://api.pagerduty.com/users/P23PCRC",
"type": "user_reference"
}
}
],
"total": 2
"total": 3
}`))
})

Expand Down Expand Up @@ -124,8 +146,30 @@ func TestGlobalEventOrchestrationCacheVariableList(t *testing.T) {
Type: "user_reference",
},
},
{
ID: "fffd20a2-8240-4df3-b996-964968464a3f",
Name: "example_3",
Configuration: &EventOrchestrationCacheVariableConfiguration{
Type: "external_data",
DataType: "boolean",
TTLSeconds: 1200,
},
CreatedAt: "2025-02-07T18:50:58Z",
CreatedBy: &UserReference{
ID: "P24PCRC",
Self: "https://api.pagerduty.com/users/P24PCRC",
Type: "user_reference",
},
DataEndpoint: "https://api.pagerduty.com/event_orchestrations/a64f9c87-6adc-4f89-a64c-2fdd8cba4639/cache_variables/fffd20a2-8240-4df3-b996-964968464a3f/data",
UpdatedAt: "2025-02-07T20:00:43Z",
UpdatedBy: &UserReference{
ID: "P23PCRC",
Self: "https://api.pagerduty.com/users/P23PCRC",
Type: "user_reference",
},
},
},
Total: 2,
Total: 3,
}

if !reflect.DeepEqual(resp, want) {
Expand Down Expand Up @@ -413,9 +457,31 @@ func TestServiceEventOrchestrationCacheVariableList(t *testing.T) {
"self": "https://api.pagerduty.com/users/P8B9WR8",
"type": "user_reference"
}
},
{
"id": "fffd20a2-8240-4df3-b996-964968464a3f",
"name": "example_3",
"configuration": {
"type": "external_data",
"data_type": "boolean",
"ttl_seconds": 1200
},
"created_at": "2025-02-07T18:50:58Z",
"created_by": {
"id": "P24PCRC",
"self": "https://api.pagerduty.com/users/P24PCRC",
"type": "user_reference"
},
"data_endpoint": "https://api.pagerduty.com/event_orchestrations/a64f9c87-6adc-4f89-a64c-2fdd8cba4639/cache_variables/fffd20a2-8240-4df3-b996-964968464a3f/data",
"updated_at": "2025-02-07T20:00:43Z",
"updated_by": {
"id": "P23PCRC",
"self": "https://api.pagerduty.com/users/P23PCRC",
"type": "user_reference"
}
}
],
"total": 2
"total": 3
}`))
})

Expand Down Expand Up @@ -474,8 +540,30 @@ func TestServiceEventOrchestrationCacheVariableList(t *testing.T) {
Type: "user_reference",
},
},
{
ID: "fffd20a2-8240-4df3-b996-964968464a3f",
Name: "example_3",
Configuration: &EventOrchestrationCacheVariableConfiguration{
Type: "external_data",
DataType: "boolean",
TTLSeconds: 1200,
},
CreatedAt: "2025-02-07T18:50:58Z",
CreatedBy: &UserReference{
ID: "P24PCRC",
Self: "https://api.pagerduty.com/users/P24PCRC",
Type: "user_reference",
},
DataEndpoint: "https://api.pagerduty.com/event_orchestrations/a64f9c87-6adc-4f89-a64c-2fdd8cba4639/cache_variables/fffd20a2-8240-4df3-b996-964968464a3f/data",
UpdatedAt: "2025-02-07T20:00:43Z",
UpdatedBy: &UserReference{
ID: "P23PCRC",
Self: "https://api.pagerduty.com/users/P23PCRC",
Type: "user_reference",
},
},
},
Total: 2,
Total: 3,
}

if !reflect.DeepEqual(resp, want) {
Expand All @@ -491,9 +579,9 @@ func TestServiceOrchestrationCacheVariableCreate(t *testing.T) {
input := &EventOrchestrationCacheVariable{
Name: "create_example",
Configuration: &EventOrchestrationCacheVariableConfiguration{
Type: "recent_value",
Source: "event.custom_details.error",
Regex: "[0-9]+",
Type: "external_data",
DataType: "string",
TTLSeconds: 900,
},
}
url := fmt.Sprintf("%s/services/%s/cache_variables/", eventOrchestrationBaseUrl, oId)
Expand All @@ -510,9 +598,9 @@ func TestServiceOrchestrationCacheVariableCreate(t *testing.T) {
"id": "43f061e0-e92b-49f0-91a0-be79404319fc",
"name": "create_example",
"configuration": {
"type": "recent_value",
"source": "event.custom_details.error",
"regex": "[0-9]+"
"type": "external_data",
"data_type": "string",
"ttl_seconds": 900
}
}
}`))
Expand All @@ -528,9 +616,9 @@ func TestServiceOrchestrationCacheVariableCreate(t *testing.T) {
ID: "43f061e0-e92b-49f0-91a0-be79404319fc",
Name: "create_example",
Configuration: &EventOrchestrationCacheVariableConfiguration{
Type: "recent_value",
Source: "event.custom_details.error",
Regex: "[0-9]+",
Type: "external_data",
DataType: "string",
TTLSeconds: 900,
},
}

Expand Down