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

CI fixes & Cleanup #304

Merged
merged 11 commits into from
Jan 13, 2025
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
uses: actions/setup-go@37335c7bb261b353407cff977110895fa0b4f7d8
with:
go-version: ${{ matrix.go-version }}
- name: Acceptance Tests
- name: Clean up any resources
env:
CORALOGIX_ENV: ${{ secrets.CORALOGIX_ENV }}
CORALOGIX_API_KEY: ${{ secrets.CORALOGIX_API_KEY }}
TEST_TEAM_ID: ${{ secrets.TEST_TEAM_ID }}
AWS_TEST_ROLE: ${{ secrets.AWS_TEST_ROLE }}
run: |
go run scripts/delete-all-cx-resources.go
go run scripts/cx-test-resource-cleanup.go
45 changes: 0 additions & 45 deletions coralogix/clientset/callPropertiesCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,15 @@ package clientset

import (
"context"
"crypto/tls"
"fmt"
"runtime"
"time"

"github.com/google/uuid"
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
)

type CallPropertiesCreator struct {
targetUrl string
apiKey string
correlationID string
//allowRetry bool
}

type CallProperties struct {
Expand All @@ -41,43 +33,6 @@ type CallProperties struct {
CallOptions []grpc.CallOption
}

func (c CallPropertiesCreator) GetCallProperties(ctx context.Context) (*CallProperties, error) {
ctx = createAuthContext(ctx, c.apiKey, c.correlationID)

conn, err := createSecureConnection(c.targetUrl)
if err != nil {
return nil, err
}

callOptions := createCallOptions()

return &CallProperties{Ctx: ctx, Connection: conn, CallOptions: callOptions}, nil
}

func createCallOptions() []grpc.CallOption {
var callOptions []grpc.CallOption
callOptions = append(callOptions, grpc_retry.WithMax(5))
callOptions = append(callOptions, grpc_retry.WithBackoff(grpc_retry.BackoffLinear(time.Second)))
return callOptions
}

func createSecureConnection(targetUrl string) (*grpc.ClientConn, error) {
return grpc.Dial(targetUrl,
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
}

func createAuthContext(ctx context.Context, apiKey string, correlationID string) context.Context {
md := metadata.New(map[string]string{
"Authorization": fmt.Sprintf("Bearer %s", apiKey),
"x-cx-sdk-language": "go",
"x-cx-go-version": runtime.Version(),
"x-cx-sdk-version": "terraform-1.18.16",
"x-cx-correlation-id": correlationID,
})
ctx = metadata.NewOutgoingContext(ctx, md)
return ctx
}

func NewCallPropertiesCreator(targetUrl, apiKey string) *CallPropertiesCreator {
return &CallPropertiesCreator{
targetUrl: targetUrl,
Expand Down
3 changes: 2 additions & 1 deletion coralogix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func OldProvider() *oldSchema.Provider {
if cxEnv == "" || len(cxEnv) > 3 {
cxEnv = targetUrl
}

return clientset.NewClientSet(cxEnv, apiKey, targetUrl), nil
},
}
Expand Down Expand Up @@ -303,7 +304,7 @@ func (p *coralogixProvider) Configure(ctx context.Context, req provider.Configur
} else {
targetUrl = fmt.Sprintf("ng-api-grpc.%s:443", domain)
}
if len(env) > 3 {
if domain != "" {
env = targetUrl
}

Expand Down
2 changes: 2 additions & 0 deletions coralogix/resource_coralogix_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,7 @@ func extractAlertProperties(ctx context.Context, plan *AlertResourceModel) (*cxs
if diags.HasError() {
return nil, diags
}

labels, diags := typeMapToStringMap(ctx, plan.Labels)

if diags.HasError() {
Expand All @@ -1724,6 +1725,7 @@ func extractAlertProperties(ctx context.Context, plan *AlertResourceModel) (*cxs
IncidentsSettings: incidentsSettings,
NotificationGroup: notificationGroup,
EntityLabels: labels,
// Schedule is set in the next step
}

alertProperties, diags = expandAlertsSchedule(ctx, alertProperties, plan.Schedule)
Expand Down
8 changes: 4 additions & 4 deletions coralogix/resource_coralogix_slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,28 @@ func (S SLOResourceValidator) ValidateResource(ctx context.Context, req resource
resp.Diagnostics = diags
return
}
if config.Type.ValueString() == "latency" && (config.ThresholdMicroseconds.IsNull() || config.ThresholdMicroseconds.IsUnknown()) {
if config.Type.ValueString() == "latency" && config.ThresholdMicroseconds.IsNull() {
resp.Diagnostics.AddError(
"ThresholdMicroseconds is required when type is latency",
"ThresholdMicroseconds is required when type is latency",
)
return
}
if config.Type.ValueString() == "latency" && (config.ThresholdSymbolType.IsNull() || config.ThresholdSymbolType.IsUnknown()) {
if config.Type.ValueString() == "latency" && config.ThresholdSymbolType.IsNull() {
resp.Diagnostics.AddError(
"ThresholdSymbolType is required when type is latency",
"ThresholdSymbolType is required when type is latency",
)
return
}
if config.Type.ValueString() == "error" && !(config.ThresholdMicroseconds.IsNull() || config.ThresholdMicroseconds.IsUnknown()) {
if config.Type.ValueString() == "error" && !config.ThresholdMicroseconds.IsNull() {
resp.Diagnostics.AddError(
"ThresholdMicroseconds is not allowed when type is error",
"ThresholdMicroseconds is not allowed when type is error",
)
return
}
if config.Type.ValueString() == "error" && !(config.ThresholdSymbolType.IsNull() || config.ThresholdSymbolType.IsUnknown()) {
if config.Type.ValueString() == "error" && !config.ThresholdSymbolType.IsNull() {
resp.Diagnostics.AddError(
"ThresholdSymbolType is not allowed when type is error",
"ThresholdSymbolType is not allowed when type is error",
Expand Down
39 changes: 21 additions & 18 deletions coralogix/resource_coralogix_slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,25 @@ func testAccSLOCheckDestroy(s *terraform.State) error {
}

func testAccCoralogixResourceSLO() string {
return `resource "coralogix_slo" "test" {
name = "coralogix_slo_example"
service_name = "service_name"
description = "description"
target_percentage = 30
type = "latency"
threshold_microseconds = 1000000
threshold_symbol_type = "greater"
period = "7_days"
filters = [
{
field = "severity"
compare_type = "is"
field_values = ["error", "warning"]
},
]
}
`
return `
variable "test" {
type = number
default = 1000000
}
resource "coralogix_slo" "test" {
name = "coralogix_slo_example"
service_name = "service_name"
description = "description"
target_percentage = 30
type = "latency"
threshold_microseconds = var.test
threshold_symbol_type = "greater"
period = "7_days"
filters = [{
field = "severity"
compare_type = "is"
field_values = ["error", "warning"]
}]
}
`
}
2 changes: 1 addition & 1 deletion docs/guides/alerts-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This guide provides step-by-step instructions on how to use the Terraform migrat

## Prerequisites
0. **Get the scripts**:
- Download from [https://github.com/coralogix/coralogix-management-sdk/tree/master/tools/terraform-importer]()
- Download from https://github.com/coralogix/coralogix-management-sdk/tree/master/tools/terraform-importer
1. **Terraform Installed**:
- Ensure you have Terraform installed. You can download it [here](https://www.terraform.io/downloads).
2. **Go Installed**:
Expand Down
37 changes: 19 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ require (
github.com/google/uuid v1.6.0
github.com/grafana/grafana-api-golang-client v0.27.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/hashicorp/terraform-plugin-docs v0.19.4
github.com/hashicorp/terraform-plugin-framework v1.10.0
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-mux v0.16.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/hashicorp/terraform-plugin-testing v1.9.0
github.com/hashicorp/terraform-plugin-docs v0.20.1
github.com/hashicorp/terraform-plugin-framework v1.13.0
github.com/hashicorp/terraform-plugin-framework-validators v0.16.0
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-mux v0.17.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848
google.golang.org/grpc v1.68.1
google.golang.org/protobuf v1.35.2
google.golang.org/grpc v1.69.2
google.golang.org/protobuf v1.36.2
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -33,7 +33,7 @@ require (
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
Expand All @@ -45,14 +45,15 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/go-plugin v1.6.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hc-install v0.7.0 // indirect
github.com/hashicorp/hcl/v2 v2.21.0 // indirect
github.com/hashicorp/hc-install v0.9.0 // indirect
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.21.0 // indirect
github.com/hashicorp/terraform-json v0.22.1 // indirect
github.com/hashicorp/terraform-json v0.23.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
Expand All @@ -74,17 +75,17 @@ require (
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yuin/goldmark v1.7.1 // indirect
github.com/yuin/goldmark v1.7.7 // indirect
github.com/yuin/goldmark-meta v1.1.0 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
golang.org/x/crypto v0.30.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
Expand Down
Loading
Loading