Skip to content

Commit

Permalink
patch - printing requests for internal errors (#178)
Browse files Browse the repository at this point in the history
* patch - printing requests for internal errors

* pre-commit linter changes

* fixing comments

* fixing comments

* fixing comments

* fixing CHANGELOG
  • Loading branch information
OrNovo authored Dec 10, 2023
1 parent 820d22f commit 2c2aea9
Show file tree
Hide file tree
Showing 45 changed files with 707 additions and 988 deletions.
19 changes: 12 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,38 +336,43 @@ DEVELOPERS:
* using grpc endpoint instead of the REST endpoint.
* moved to `plugin-framework`.

Release 1.8.0
## Release 1.8.0
Breaking Changes:
#### resource/coralogix_dashboard
* schemas where changed to support the new dashboard widgets and more convenient schema.

Release 1.8.6
## Release 1.8.6
New Features:
#### resource/coralogix_alert
* Adding support for `flow.group_by`.

Release 1.8.10
## Release 1.8.10
New Features:
#### resource/coralogix_dashboard
* Adding limitation for `layout.sections` length (will support few sections in the future).
* is_visible is true by default (for all is_visible fields).
* Removing `gauge.query.logs/spans.aggregation` from schema.

Release 1.8.11
## Release 1.8.11
New Features:
#### resource/coralogix_dashboard
* Adding support for `markdown` and `horizonal_bar_chart` widgets.
* Adding support for `color_scheme` and `sort_by` for `bar_chart`.

Release 1.9.0
## Release 1.9.0
Breaking Changes:
#### resource/coralogix_webhook
* All webhook types changed from `TypeList` to `SingleNestedAttribute` e.g. - `slack { }` => `slack = { }`.
* Linkage between webhook and alert was changed from webhook's `id` to webhook's `external_id`. e.g.- `integration_id = coralogix_webhook.slack_webhook.id` => `integration_id = coralogix_webhook.slack_webhook.external_id`

Release 1.10.0
## Release 1.10.0
Breaking Changes:
#### resource/coralogix_recording_rules_groups_set
* `group` was changed to `groups` and from `TypeSet` to `SetNestedAttribute`. e.g. - `group { }` => `groups = [{ }]`.
* `group.rule` was changed to `groups.rules` and from `TypeList` to `ListNestedAttribute`. e.g. - `rule { }` => `rules = [{ }]`.
* this version contains a [State Upgrader](https://developer.hashicorp.com/terraform/plugin/framework/migrating/resources/state-upgrade#framework). It will upgrade the state to the new schema. Please make sure to back up your state before upgrading.
* this version contains a [State Upgrader](https://developer.hashicorp.com/terraform/plugin/framework/migrating/resources/state-upgrade#framework). It will upgrade the state to the new schema. Please make sure to back up your state before upgrading.

## Release 1.10.4
Breaking Changes:
#### resource/coralogix_tco_policy_overrides
* the resource was deprecated and removed.
57 changes: 4 additions & 53 deletions coralogix/clientset/enrichments-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import (
"context"

enrichment "terraform-provider-coralogix/coralogix/clientset/grpc/enrichment/v1"

"google.golang.org/protobuf/types/known/wrapperspb"
)

type EnrichmentsClient struct {
callPropertiesCreator *CallPropertiesCreator
}

func (e EnrichmentsClient) CreateEnrichments(ctx context.Context, req []*enrichment.EnrichmentRequestModel) ([]*enrichment.Enrichment, error) {
func (e EnrichmentsClient) CreateEnrichments(ctx context.Context, req *enrichment.AddEnrichmentsRequest) ([]*enrichment.Enrichment, error) {
callProperties, err := e.callPropertiesCreator.GetCallProperties(ctx)
if err != nil {
return nil, err
Expand All @@ -22,14 +20,13 @@ func (e EnrichmentsClient) CreateEnrichments(ctx context.Context, req []*enrichm
defer conn.Close()
client := enrichment.NewEnrichmentServiceClient(conn)

addReq := &enrichment.AddEnrichmentsRequest{RequestEnrichments: req}
resp, err := client.AddEnrichments(callProperties.Ctx, addReq, callProperties.CallOptions...)
resp, err := client.AddEnrichments(callProperties.Ctx, req, callProperties.CallOptions...)
if err != nil {
return nil, err
}

enrichments := resp.GetEnrichments()
from := len(enrichments) - len(req)
from := len(enrichments) - len(req.GetRequestEnrichments())
to := len(enrichments)
return enrichments[from:to], nil
}
Expand Down Expand Up @@ -84,44 +81,7 @@ func (e EnrichmentsClient) GetCustomEnrichments(ctx context.Context, customEnric
return result, nil
}

func (e EnrichmentsClient) UpdateEnrichments(ctx context.Context, ids []uint32, req []*enrichment.EnrichmentRequestModel) ([]*enrichment.Enrichment, error) {
err := e.DeleteEnrichments(ctx, ids)
if err != nil {
return nil, err
}
return e.CreateEnrichments(ctx, req)
}

func (e EnrichmentsClient) DeleteEnrichments(ctx context.Context, ids []uint32) error {
callProperties, err := e.callPropertiesCreator.GetCallProperties(ctx)
if err != nil {
return err
}

conn := callProperties.Connection
defer conn.Close()

client := enrichment.NewEnrichmentServiceClient(conn)

enrichmentIds := make([]*wrapperspb.UInt32Value, 0, len(ids))
for _, id := range ids {
enrichmentIds = append(enrichmentIds, wrapperspb.UInt32(id))
}

req := &enrichment.RemoveEnrichmentsRequest{
EnrichmentIds: enrichmentIds,
}

_, err = client.RemoveEnrichments(callProperties.Ctx, req, callProperties.CallOptions...)
return err
}

func (e EnrichmentsClient) DeleteEnrichmentsByType(ctx context.Context, enrichmentType string) error {
enrichmentsToDelete, err := e.GetEnrichmentsByType(ctx, enrichmentType)
if err != nil {
return err
}

func (e EnrichmentsClient) DeleteEnrichments(ctx context.Context, req *enrichment.RemoveEnrichmentsRequest) error {
callProperties, err := e.callPropertiesCreator.GetCallProperties(ctx)
if err != nil {
return err
Expand All @@ -132,15 +92,6 @@ func (e EnrichmentsClient) DeleteEnrichmentsByType(ctx context.Context, enrichme

client := enrichment.NewEnrichmentServiceClient(conn)

enrichmentIds := make([]*wrapperspb.UInt32Value, 0, len(enrichmentsToDelete))
for _, enrichment := range enrichmentsToDelete {
enrichmentIds = append(enrichmentIds, wrapperspb.UInt32(enrichment.GetId()))
}

req := &enrichment.RemoveEnrichmentsRequest{
EnrichmentIds: enrichmentIds,
}

_, err = client.RemoveEnrichments(callProperties.Ctx, req, callProperties.CallOptions...)
return err
}
Expand Down
3 changes: 2 additions & 1 deletion coralogix/clientset/recording-rules-groups-sets-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package clientset
import (
"context"

"google.golang.org/protobuf/types/known/emptypb"
rrg "terraform-provider-coralogix/coralogix/clientset/grpc/recording-rules-groups-sets/v1"

"google.golang.org/protobuf/types/known/emptypb"
)

type RecordingRulesGroupsSetsClient struct {
Expand Down
18 changes: 11 additions & 7 deletions coralogix/data_source_coralogix_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import (
"fmt"
"log"

"google.golang.org/protobuf/encoding/protojson"

"terraform-provider-coralogix/coralogix/clientset"
actions "terraform-provider-coralogix/coralogix/clientset/grpc/actions/v2"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"terraform-provider-coralogix/coralogix/clientset"
actions "terraform-provider-coralogix/coralogix/clientset/grpc/actions/v2"

"google.golang.org/protobuf/types/known/wrapperspb"
)
Expand Down Expand Up @@ -47,10 +50,10 @@ func (d *ActionDataSource) Configure(_ context.Context, req datasource.Configure
d.client = clientSet.Actions()
}

func (d *ActionDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *ActionDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
var r ActionResource
var resourceResp resource.SchemaResponse
r.Schema(nil, resource.SchemaRequest{}, &resourceResp)
r.Schema(ctx, resource.SchemaRequest{}, &resourceResp)

resp.Schema = frameworkDatasourceSchemaFromFrameworkResourceSchema(resourceResp.Schema)
}
Expand All @@ -65,7 +68,8 @@ func (d *ActionDataSource) Read(ctx context.Context, req datasource.ReadRequest,
//Get refreshed Action value from Coralogix
id := data.ID.ValueString()
log.Printf("[INFO] Reading Action: %s", id)
getActionResp, err := d.client.GetAction(ctx, &actions.GetActionRequest{Id: wrapperspb.String(id)})
getActionReq := &actions.GetActionRequest{Id: wrapperspb.String(id)}
getActionResp, err := d.client.GetAction(ctx, getActionReq)
if err != nil {
log.Printf("[ERROR] Received error: %#v", err)
if status.Code(err) == codes.NotFound {
Expand All @@ -77,12 +81,12 @@ func (d *ActionDataSource) Read(ctx context.Context, req datasource.ReadRequest,
} else {
resp.Diagnostics.AddError(
"Error reading Action",
handleRpcErrorNewFramework(err, "Action"),
formatRpcErrors(err, getActionURL, protojson.Format(getActionReq)),
)
}
return
}
log.Printf("[INFO] Received Action: %#v", getActionResp)
log.Printf("[INFO] Received Action: %s", protojson.Format(getActionResp))

data = flattenAction(getActionResp.GetAction())

Expand Down
7 changes: 5 additions & 2 deletions coralogix/data_source_coralogix_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"log"

"google.golang.org/protobuf/encoding/protojson"

"terraform-provider-coralogix/coralogix/clientset"
alertsv1 "terraform-provider-coralogix/coralogix/clientset/grpc/alerts/v2"

Expand Down Expand Up @@ -35,11 +37,12 @@ func dataSourceCoralogixAlertRead(ctx context.Context, d *schema.ResourceData, m
log.Printf("[INFO] Reading alert %s", id)
alertResp, err := meta.(*clientset.ClientSet).Alerts().GetAlert(ctx, getAlertRequest)
if err != nil {
reqStr := protojson.Format(getAlertRequest)
log.Printf("[ERROR] Received error: %#v", err)
return handleRpcErrorWithID(err, "alert", id.GetValue())
return diag.Errorf(formatRpcErrors(err, getAlertURL, reqStr))
}
alert := alertResp.GetAlert()
log.Printf("[INFO] Received alert: %#v", alert)
log.Printf("[INFO] Received alert: %s", protojson.Format(alert))

d.SetId(alert.GetId().GetValue())

Expand Down
16 changes: 10 additions & 6 deletions coralogix/data_source_coralogix_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import (
"fmt"
"log"

"terraform-provider-coralogix/coralogix/clientset"
dashboards "terraform-provider-coralogix/coralogix/clientset/grpc/coralogix-dashboards/v1"

"google.golang.org/protobuf/encoding/protojson"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/wrapperspb"
"terraform-provider-coralogix/coralogix/clientset"
dashboards "terraform-provider-coralogix/coralogix/clientset/grpc/coralogix-dashboards/v1"
)

var _ datasource.DataSourceWithConfigure = &DashboardDataSource{}
Expand Down Expand Up @@ -46,10 +49,10 @@ func (d *DashboardDataSource) Configure(_ context.Context, req datasource.Config
d.client = clientSet.Dashboards()
}

func (d *DashboardDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *DashboardDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
var r DashboardResource
var resourceResp resource.SchemaResponse
r.Schema(nil, resource.SchemaRequest{}, &resourceResp)
r.Schema(ctx, resource.SchemaRequest{}, &resourceResp)

resp.Schema = frameworkDatasourceSchemaFromFrameworkResourceSchema(resourceResp.Schema)
}
Expand All @@ -64,7 +67,8 @@ func (d *DashboardDataSource) Read(ctx context.Context, req datasource.ReadReque
//Get refreshed Dashboard value from Coralogix
id := data.ID.ValueString()
log.Printf("[INFO] Reading Dashboard: %s", id)
getDashboardResp, err := d.client.GetDashboard(ctx, &dashboards.GetDashboardRequest{DashboardId: wrapperspb.String(id)})
getDashboardReq := &dashboards.GetDashboardRequest{DashboardId: wrapperspb.String(id)}
getDashboardResp, err := d.client.GetDashboard(ctx, getDashboardReq)
if err != nil {
log.Printf("[ERROR] Received error: %#v", err)
if status.Code(err) == codes.NotFound {
Expand All @@ -76,7 +80,7 @@ func (d *DashboardDataSource) Read(ctx context.Context, req datasource.ReadReque
} else {
resp.Diagnostics.AddError(
"Error reading Dashboard",
handleRpcErrorNewFramework(err, "Dashboard"),
formatRpcErrors(err, getDashboardURL, protojson.Format(getDashboardReq)),
)
}
return
Expand Down
7 changes: 5 additions & 2 deletions coralogix/data_source_coralogix_data_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"terraform-provider-coralogix/coralogix/clientset"
enrichmentv1 "terraform-provider-coralogix/coralogix/clientset/grpc/enrichment/v1"

"google.golang.org/protobuf/encoding/protojson"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"google.golang.org/protobuf/types/known/wrapperspb"
Expand All @@ -33,9 +35,10 @@ func dataSourceCoralogixDataSetRead(ctx context.Context, d *schema.ResourceData,
enrichmentResp, err := meta.(*clientset.ClientSet).DataSet().GetDataSet(ctx, req)
if err != nil {
log.Printf("[ERROR] Received error: %#v", err)
return handleRpcErrorWithID(err, "custom-enrichment-data", id)
reqStr := protojson.Format(req)
return diag.Errorf(formatRpcErrors(err, getDataSetURL, reqStr))
}
log.Printf("[INFO] Received custom-enrichment-data: %#v", enrichmentResp)
log.Printf("[INFO] Received custom-enrichment-data: %s", protojson.Format(enrichmentResp))

d.SetId(uint32ToStr(enrichmentResp.GetCustomEnrichment().GetId()))

Expand Down
5 changes: 4 additions & 1 deletion coralogix/data_source_coralogix_enrichment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"terraform-provider-coralogix/coralogix/clientset"
enrichmentv1 "terraform-provider-coralogix/coralogix/clientset/grpc/enrichment/v1"

"google.golang.org/protobuf/encoding/protojson"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -39,8 +41,9 @@ func dataSourceCoralogixEnrichmentRead(ctx context.Context, d *schema.ResourceDa
enrichmentResp, err = meta.(*clientset.ClientSet).Enrichments().GetCustomEnrichments(ctx, strToUint32(id))
}
if err != nil {
reqStr := protojson.Format(&enrichmentv1.GetEnrichmentsRequest{})
log.Printf("[ERROR] Received error: %#v", err)
return handleRpcError(err, "enrichment")
return diag.Errorf(formatRpcErrors(err, getEnrichmentsURL, reqStr))
}
log.Printf("[INFO] Received enrichment: %#v", enrichmentResp)
d.SetId(id)
Expand Down
18 changes: 11 additions & 7 deletions coralogix/data_source_coralogix_events2meric.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import (
"fmt"
"log"

"terraform-provider-coralogix/coralogix/clientset"
e2m "terraform-provider-coralogix/coralogix/clientset/grpc/events2metrics/v2"

"google.golang.org/protobuf/encoding/protojson"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/wrapperspb"
"terraform-provider-coralogix/coralogix/clientset"
e2m "terraform-provider-coralogix/coralogix/clientset/grpc/events2metrics/v2"
)

var _ datasource.DataSourceWithConfigure = &Events2MetricDataSource{}
Expand Down Expand Up @@ -46,10 +49,10 @@ func (d *Events2MetricDataSource) Configure(_ context.Context, req datasource.Co
d.client = clientSet.Events2Metrics()
}

func (d *Events2MetricDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *Events2MetricDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
var r Events2MetricResource
var resourceResp resource.SchemaResponse
r.Schema(nil, resource.SchemaRequest{}, &resourceResp)
r.Schema(ctx, resource.SchemaRequest{}, &resourceResp)

resp.Schema = frameworkDatasourceSchemaFromFrameworkResourceSchema(resourceResp.Schema)
}
Expand All @@ -64,7 +67,8 @@ func (d *Events2MetricDataSource) Read(ctx context.Context, req datasource.ReadR
//Get refreshed Events2Metric value from Coralogix
id := data.ID.ValueString()
log.Printf("[INFO] Reading Events2metric: %s", id)
getE2MResp, err := d.client.GetEvents2Metric(ctx, &e2m.GetE2MRequest{Id: wrapperspb.String(id)})
getE2MReq := &e2m.GetE2MRequest{Id: wrapperspb.String(id)}
getE2MResp, err := d.client.GetEvents2Metric(ctx, getE2MReq)
if err != nil {
log.Printf("[ERROR] Received error: %#v", err)
if status.Code(err) == codes.NotFound {
Expand All @@ -76,12 +80,12 @@ func (d *Events2MetricDataSource) Read(ctx context.Context, req datasource.ReadR
} else {
resp.Diagnostics.AddError(
"Error reading Events2Metric",
handleRpcErrorNewFramework(err, "Events2metric"),
formatRpcErrors(err, getEvents2MetricURL, protojson.Format(getE2MReq)),
)
}
return
}
log.Printf("[INFO] Received Events2metric: %#v", getE2MResp)
log.Printf("[INFO] Received Events2metric: %s", protojson.Format(getE2MResp))

data = flattenE2M(ctx, getE2MResp.GetE2M())

Expand Down
Loading

0 comments on commit 2c2aea9

Please sign in to comment.