Skip to content

Commit

Permalink
patch - adding tco_policy_traces
Browse files Browse the repository at this point in the history
  • Loading branch information
OrNovo committed Jul 27, 2023
1 parent 077c3cd commit 7628671
Show file tree
Hide file tree
Showing 10 changed files with 1,355 additions and 65 deletions.
142 changes: 108 additions & 34 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,39 @@ BREAKING CHANGES:
#### resource/alert

* `categories` ,`classes`, `computers`, `ip_addresses`, `methods` and `search_query` are not supported
filters for tracing alert, Therefore they were deleted from the tracing-alert scheme.
* `applications`,`severities` and `subsystems` filters have currently different format in tracing-alert (`field_filters`),
Therefore they were deleted from the tracing-alert scheme.
filters for tracing alert, Therefore they were deleted from the tracing-alert scheme.
* `applications`,`severities` and `subsystems` filters have currently different format in
tracing-alert (`field_filters`),
Therefore they were deleted from the tracing-alert scheme.

## Release 1.4.0

BREAKING CHANGES:

#### resource/alert

* `meta_labels` was changed to key-value map. (e.g. - `meta_labels {key = "alert_type" value = "security"} meta_labels {key = "security_severity" value = "high"}` => `meta_labels = {alert_type = "security" security_severity = "high" }`).
([example-usage](docs/resources/alert.md#standard-alert)).
* `meta_labels` was changed to key-value map. (e.g.
- `meta_labels {key = "alert_type" value = "security"} meta_labels {key = "security_severity" value = "high"}`
=> `meta_labels = {alert_type = "security" security_severity = "high" }`).
([example-usage](docs/resources/alert.md#standard-alert)).
* `scheduling.time_frames` was changed to `time_frame`.
* `standard.occurrences_threshold` and `tracing.occurrences_threshold` were changed to `threshold`.
* `ratio.queries_ratio` was changed to `ratio_threshold`.
* `notification` was changed to list of `notifications_group` and have entire different schema ([nested-schema-for-notifications](docs/resources/alert.md#nested-schema-for-notifications_group)).
* `notification.ignore_infinity` was moved to `ratio.condition.ignore_infinity` and `time_relative.condition.ignore_infinity`.
* `notification` was changed to list of `notifications_group` and have entire different
schema ([nested-schema-for-notifications](docs/resources/alert.md#nested-schema-for-notifications_group)).
* `notification.ignore_infinity` was moved to `ratio.condition.ignore_infinity`
and `time_relative.condition.ignore_infinity`.
* `notification.notify_every_min` was changed to `notifications_group.notification.retriggering_period_minutes`.
* `notification.on_trigger_and_resolved` (boolean) was changed to `notifications_group.notification.notify_on` (string).
* `notification.recipients.webhook_id` replaced with `notifications_group.notification.integration_id` and should contain the integration's (webhook's) id instead of the integration's name.
* flow-alert's (`flow`) schema was fixed. Any earlier version contained wrong schema of flow-alert. ([nested-schema-for-flow](docs/resources/alert.md#nested-schema-for-flow)).
* `tracing.field_filters` was removed, and `tracing.applications`, `tracing.applications` and `tracing.services` were added instead.
* `notification.recipients.webhook_id` replaced with `notifications_group.notification.integration_id` and should
contain the integration's (webhook's) id instead of the integration's name.
* flow-alert's (`flow`) schema was fixed. Any earlier version contained wrong schema of
flow-alert. ([nested-schema-for-flow](docs/resources/alert.md#nested-schema-for-flow)).
* `tracing.field_filters` was removed, and `tracing.applications`, `tracing.applications` and `tracing.services` were
added instead.
* `tracing.tag_filters` was changed to `tracing.tag_filter` and contains only `field` and `values`.
* `tracing.tag_filter.values`, `tracing.applications`, `tracing.applications` and `tracing.services` have the same format as the other alerts' filters. ([example-usage](docs/resources/alert.md#tracing-alert)).
* `tracing.tag_filter.values`, `tracing.applications`, `tracing.applications` and `tracing.services` have the same
format as the other alerts' filters. ([example-usage](docs/resources/alert.md#tracing-alert)).
* `tracing.latency_threshold_ms` was changed to `latency_threshold_milliseconds`.

## Release 1.4.4
Expand All @@ -118,22 +127,26 @@ BREAKING CHANGES:

#### resource/alert

* `notifications_group.group_by_fields` was changed from _TypeSet_ (doesn't keep order of declaration) to _TypeList_ (keeps order of declaration). This change can cause to diffs in state.
* `notifications_group.group_by_fields` was changed from _TypeSet_ (doesn't keep order of declaration) to _TypeList_ (
keeps order of declaration). This change can cause to diffs in state.

## Release 1.5.0

BREAKING CHANGES:

#### resource/events2metric (~~logs2metric~~)

* resource and data-source name _logs2metric_ was changed to _events2metric_ and contains `logs_query` and `span_query` option.
* resource and data-source name _logs2metric_ was changed to _events2metric_ and contains `logs_query` and `span_query`
option.

## Release 1.5.2

FEATURES:

#### resource/events2metric
* Adding [aggregations](docs/resources/events2metric.md#nested-schema-for-metric_fieldsaggregations) option to `metric_fields`.

* Adding [aggregations](docs/resources/events2metric.md#nested-schema-for-metric_fieldsaggregations) option
to `metric_fields`.

## Release 1.5.3

Expand All @@ -147,8 +160,11 @@ BREAKING CHANGES:
BUG FIXING:

#### resource/tco_policy
* Fixing [TF doesn't detect manually deleted resources](https://coralogix-dev.slack.com/archives/C04CV0JG36H/p1683820712917899)
* Fixing [Order of policies can't be manged by TF](https://coralogix-dev.slack.com/archives/C04CV0JG36H/p1681995853325159)

*
Fixing [TF doesn't detect manually deleted resources](https://coralogix-dev.slack.com/archives/C04CV0JG36H/p1683820712917899)
*
Fixing [Order of policies can't be manged by TF](https://coralogix-dev.slack.com/archives/C04CV0JG36H/p1681995853325159)

FEATURES:

Expand All @@ -169,105 +185,163 @@ FEATURES:
BREAKING CHANGES:

#### resource/recording_rules_group

* Deprecated, and replaced with [recording_rules_groups_set](./docs/resources/recording_rules_groups_set.md) .

## Release 1.5.6

#### resource/tco_policy
* Fixing [TF doesn't detect manually deleted resources](https://coralogix-dev.slack.com/archives/C04CV0JG36H/p1683820712917899)

*
Fixing [TF doesn't detect manually deleted resources](https://coralogix-dev.slack.com/archives/C04CV0JG36H/p1683820712917899)

## Release 1.5.7

BUG FIXING:

#### resource/alert

* Fixing - received an error when updating promql alert condition from less_than to more_than

## Release 1.5.8

BREAKING CHANGES:

#### resource/coralogix_dashboard
* for all the new line chart widgets - `query`, `series_name_template`, `series_count_limit`, `unit` and `scale_type` fields were deprecated. They will be part of `query_definition` now.

* for all the new line chart widgets - `query`, `series_name_template`, `series_count_limit`, `unit` and `scale_type`
fields were deprecated. They will be part of `query_definition` now.
* all lists of objects names' 's' suffix was removed (e.g. - `widgets` => `widget`).

## Release 1.5.9

BUG FIXING:
#### resource/coralogix_alert
* Fixing - tracing alert with `tracing.tag_filter` and `tracing.applications`/`tracing.services`/`tracing.services` filters doesn't work for 'equal' operator.

#### resource/coralogix_alert

* Fixing - tracing alert with `tracing.tag_filter` and `tracing.applications`/`tracing.services`/`tracing.services`
filters doesn't work for 'equal' operator.

FEATURES:

#### resource/coralogix_alert
* Adding support for 'notEquals' operator for `tracing.tag_filter` and `tracing.applications`/`tracing.services`/`tracing.services` filters.

* Adding support for 'notEquals' operator for `tracing.tag_filter` and `tracing.applications`/`tracing.services`
/`tracing.services` filters.

## Release 1.6.0

BREAKING CHANGES:

#### resource/coralogix_events2metric
**Please note** - 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.

**Please note** - 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.

* `logs_query` type was changed from `Block List, Max: 1` to `Attributes`.
* `spans_query` type was changed from `Block List, Max: 1` to `Attributes`.
* `metric_fields` type was changed from `Block Set` to `Attributes Map`, and `metric_fields`'s `target_base_metric_name` was changed to the map's key. e.g. - `metric_fields {target_base_metric_name = "metric_name" ...}` => `metric_fields = {"metric_name" = {...}}`.
* `metric_fields` type was changed from `Block Set` to `Attributes Map`, and `metric_fields`'s `target_base_metric_name`
was changed to the map's key. e.g. - `metric_fields {target_base_metric_name = "metric_name" ...}`
=> `metric_fields = {"metric_name" = {...}}`.
* `metric_fields`'s `aggregations` type was changed from `Block List, Max: 1` to `Attributes`.
* All `aggregations`'s fields (`avg`, `count`, `histogram`, `max`, `min`, `samples`, `sum`) types where changed from `Block List, Max: 1` `Attributes`.
* `metric_labels` type was changed from `Block Set` to `Attributes Map`, and `metric_labels`'s `target_label_name` was changed to the map's key. e.g. - `metric_labels {target_label_name = "label_name" ...}` => `metric_labels = {"label_name" = {...}}`.
* All `aggregations`'s fields (`avg`, `count`, `histogram`, `max`, `min`, `samples`, `sum`) types where changed
from `Block List, Max: 1` `Attributes`.
* `metric_labels` type was changed from `Block Set` to `Attributes Map`, and `metric_labels`'s `target_label_name` was
changed to the map's key. e.g. - `metric_labels {target_label_name = "label_name" ...}`
=> `metric_labels = {"label_name" = {...}}`.

BUG FIXING:

#### resource/coralogix_events2metric
* Fixing - [`aggregations` cannot be updated after creation](https://github.com/coralogix/terraform-provider-coralogix/issues/115).

* Fixing
- [`aggregations` cannot be updated after creation](https://github.com/coralogix/terraform-provider-coralogix/issues/115)
.

## Release 1.6.1

FEATURES:

#### resource/coralogix_alert

* Adding support for `more_than_usual` condition for `metric.promql` alert.

## Release 1.6.2

FEATURES:

#### resource/coralogix_tco_policy

* Adding support for `archive_retention_id`.

## Release 1.6.3

DEVELOPERS:

#### resource/coralogix_actions

* Resource and Data Source were moved to plugin-framework.

## Release 1.6.4

Breaking Changes:

#### resource/coralogix_alert

* `ratio` and `time_relative`'s `condition`'s `ignore_infinity` conflicts with `condition`'s `less_than`.

BUG FIXING:

#### resource/coralogix_tco_policy

* Fixing - getting panic on creation errors.

## Release 1.6.5

INTERNAL CHANGES:

#### resource/coralogix_tco_policy

* `tco_policy` and `tco_policy_override` endpoints were changed.

## Release 1.7.0

Breaking Changes:

#### resource/coralogix_tco_policy
**Please note** - 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.
* `subsystem_name` was changed to `subsystems` and have different structure e.g. -
`subsystem_name {
is = true

**Please note** - 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.

* `subsystem_name` was changed to `subsystems` and have different structure e.g. -
`subsystem_name {
is = true
rules = ["mobile", "web"]
}` => `subsystems = {
rule_type = "is"
names = ["mobile", "web"]
}`
* `application_name` was changed to `applications` and have different structure e.g. - `application_name {
starts_with = true
rule = "prod"
rule = "prod"
}` => `applications = {
rule_type = "starts with"
names = ["prod"]
names = ["prod"]
}`

DEVELOPERS:

#### resource/coralogix_tco_policy

* using grpc endpoint instead of the REST endpoint.
* moved to `plugin-framework`.
* moved to `plugin-framework`.

## Release 1.7.1

FEATURES:

#### resource/coralogix_tco_policy_traces

* new resource - _coralogix_tco_policy_traces_
96 changes: 96 additions & 0 deletions coralogix/data_source_coralogix_tco_policy_traces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package coralogix

import (
"context"
"fmt"
"log"

"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"
tcopolicies "terraform-provider-coralogix/coralogix/clientset/grpc/tco-policies"

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

var _ datasource.DataSourceWithConfigure = &TCOPolicyTracesDataSource{}

func NewTCOPolicyTracesDataSource() datasource.DataSource {
return &TCOPolicyTracesDataSource{}
}

type TCOPolicyTracesDataSource struct {
client *clientset.TCOPoliciesClient
}

func (d *TCOPolicyTracesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_tco_policy_traces"
}

func (d *TCOPolicyTracesDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

clientSet, ok := req.ProviderData.(*clientset.ClientSet)
if !ok {
resp.Diagnostics.AddError(
"Unexpected Resource Configure Type",
fmt.Sprintf("Expected *clientset.ClientSet, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)
return
}

d.client = clientSet.TCOPolicies()
}

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

resp.Schema = frameworkDatasourceSchemaFromFrameworkResourceSchema(resourceResp.Schema)
}

func (d *TCOPolicyTracesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data TCOPolicyResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

//Get refreshed tco-policy value from Coralogix
id := data.ID.ValueString()
log.Printf("[INFO] Reading tco-policy: %s", id)
getPolicyResp, err := d.client.GetTCOPolicy(ctx, &tcopolicies.GetPolicyRequest{Id: wrapperspb.String(id)})
if err != nil {
log.Printf("[ERROR] Received error: %#v", err)
if status.Code(err) == codes.NotFound {
data.ID = types.StringNull()
resp.Diagnostics.AddWarning(
fmt.Sprintf("tco-policy %q is in state, but no longer exists in Coralogix backend", id),
fmt.Sprintf("%s will be recreated when you apply", id),
)
} else {
resp.Diagnostics.AddError(
"Error reading tco-policy",
handleRpcErrorNewFramework(err, "tco-policy"),
)
}
return
}
log.Printf("[INFO] Received tco-policy: %#v", getPolicyResp)

data = flattenTCOPolicy(getPolicyResp.GetPolicy())

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Loading

0 comments on commit 7628671

Please sign in to comment.