Skip to content

Commit 71e7cea

Browse files
committed
feat(team): add prometheus_remote_write_metrics_filter
1 parent 2b02efb commit 71e7cea

File tree

7 files changed

+84
-59
lines changed

7 files changed

+84
-59
lines changed

sysdig/internal/client/v2/model.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ type Team struct {
3535
}
3636

3737
type NamespaceFilters struct {
38-
IBMPlatformMetrics *string `json:"ibmPlatformMetrics"`
38+
IBMPlatformMetrics *string `json:"ibmPlatformMetrics,omitempty"`
39+
PrometheusRemoteWrite *string `json:"prometheusRemoteWrite,omitempty"`
3940
}
4041

4142
type UserRoles struct {

sysdig/resource_sysdig_monitor_team.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func resourceSysdigMonitorTeam() *schema.Resource {
5454
Type: schema.TypeString,
5555
Optional: true,
5656
},
57+
"prometheus_remote_write_metrics_filter": {
58+
Type: schema.TypeString,
59+
Optional: true,
60+
},
5761
"enable_ibm_platform_metrics": {
5862
Type: schema.TypeBool,
5963
Optional: true,
@@ -192,7 +196,15 @@ func resourceSysdigMonitorTeamRead(ctx context.Context, d *schema.ResourceData,
192196
_ = d.Set("user_roles", userMonitorRolesToSet(t.UserRoles))
193197
_ = d.Set("entrypoint", entrypointToSet(t.EntryPoint))
194198

195-
resourceSysdigTeamReadIBM(d, &t)
199+
var ibmPlatformMetrics *string
200+
var prometheusRemoteWrite *string
201+
if t.NamespaceFilters != nil {
202+
ibmPlatformMetrics = t.NamespaceFilters.IBMPlatformMetrics
203+
prometheusRemoteWrite = t.NamespaceFilters.PrometheusRemoteWrite
204+
}
205+
_ = d.Set("enable_ibm_platform_metrics", t.CanUseBeaconMetrics)
206+
_ = d.Set("ibm_platform_metrics", ibmPlatformMetrics)
207+
_ = d.Set("prometheus_remote_write_metrics_filter", prometheusRemoteWrite)
196208

197209
return nil
198210
}
@@ -265,7 +277,6 @@ func teamFromResourceData(d *schema.ResourceData, clientType ClientType) v2.Team
265277
canUseSysdigCapture := d.Get("can_use_sysdig_capture").(bool)
266278
canUseCustomEvents := d.Get("can_see_infrastructure_events").(bool)
267279
canUseAwsMetrics := d.Get("can_use_aws_data").(bool)
268-
canUseBeaconMetrics := false
269280
t := v2.Team{
270281
Theme: d.Get("theme").(string),
271282
Name: d.Get("name").(string),
@@ -275,7 +286,6 @@ func teamFromResourceData(d *schema.ResourceData, clientType ClientType) v2.Team
275286
CanUseSysdigCapture: &canUseSysdigCapture,
276287
CanUseCustomEvents: &canUseCustomEvents,
277288
CanUseAwsMetrics: &canUseAwsMetrics,
278-
CanUseBeaconMetrics: &canUseBeaconMetrics,
279289
DefaultTeam: d.Get("default_team").(bool),
280290
}
281291

@@ -295,7 +305,24 @@ func teamFromResourceData(d *schema.ResourceData, clientType ClientType) v2.Team
295305
t.EntryPoint.Selection = val.(string)
296306
}
297307

298-
teamFromResourceDataIBM(d, &t)
308+
canUseBeaconMetrics := d.Get("enable_ibm_platform_metrics").(bool)
309+
t.CanUseBeaconMetrics = &canUseBeaconMetrics
310+
311+
if v, ok := d.GetOk("ibm_platform_metrics"); ok {
312+
metrics := v.(string)
313+
if t.NamespaceFilters == nil {
314+
t.NamespaceFilters = &v2.NamespaceFilters{}
315+
}
316+
t.NamespaceFilters.IBMPlatformMetrics = &metrics
317+
}
318+
319+
if v, ok := d.GetOk("prometheus_remote_write_metrics_filter"); ok {
320+
metrics := v.(string)
321+
if t.NamespaceFilters == nil {
322+
t.NamespaceFilters = &v2.NamespaceFilters{}
323+
}
324+
t.NamespaceFilters.PrometheusRemoteWrite = &metrics
325+
}
299326

300327
return t
301328
}

sysdig/resource_sysdig_monitor_team_ibm_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func TestAccMonitorIBMTeam(t *testing.T) {
4141
{
4242
Config: monitorTeamWithPlatformMetricsIBM(rText()),
4343
},
44+
{
45+
Config: monitorTeamWithPlatformMetricsAndPrwMetricsIBM(rText()),
46+
},
4447
{
4548
ResourceName: "sysdig_monitor_team.sample",
4649
ImportState: true,
@@ -57,9 +60,10 @@ resource "sysdig_monitor_team" "sample" {
5760
description = "%s"
5861
scope_by = "host"
5962
filter = "container.image.repo = \"sysdig/agent\""
63+
prometheus_remote_write_metrics_filter = "kube_cluster_name in (\"test-cluster\", \"test-k8s-data\") and kube_deployment_name = \"coredns\" and my_metric starts with \"prefix\" and not my_metric contains \"prefix-test\""
6064
can_use_sysdig_capture = true
6165
can_see_infrastructure_events = true
62-
66+
6367
entrypoint {
6468
type = "Dashboards"
6569
}
@@ -78,3 +82,16 @@ resource "sysdig_monitor_team" "sample" {
7882
}
7983
}`, name)
8084
}
85+
86+
func monitorTeamWithPlatformMetricsAndPrwMetricsIBM(name string) string {
87+
return fmt.Sprintf(`
88+
resource "sysdig_monitor_team" "sample" {
89+
name = "sample-%s"
90+
enable_ibm_platform_metrics = true
91+
prometheus_remote_write_metrics_filter = "kube_cluster_name in (\"test-cluster\", \"test-k8s-data\") and kube_deployment_name = \"coredns\" and my_metric starts with \"prefix\" and not my_metric contains \"prefix-test\""
92+
93+
entrypoint {
94+
type = "Dashboards"
95+
}
96+
}`, name)
97+
}

sysdig/resource_sysdig_monitor_team_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ resource "sysdig_monitor_team" "sample" {
5454
description = "%s"
5555
scope_by = "host"
5656
filter = "container.image.repo = \"sysdig/agent\""
57+
prometheus_remote_write_metrics_filter = "kube_cluster_name in (\"test-cluster\", \"test-k8s-data\") and kube_deployment_name = \"coredns\" and my_metric starts with \"prefix\" and not my_metric contains \"prefix-test\""
5758
can_use_sysdig_capture = true
5859
can_see_infrastructure_events = true
5960
can_use_aws_data = true
60-
61+
6162
entrypoint {
6263
type = "Dashboards"
6364
}

sysdig/resource_sysdig_secure_team.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ func resourceSysdigSecureTeamRead(ctx context.Context, d *schema.ResourceData, m
200200
return diag.FromErr(err)
201201
}
202202

203-
resourceSysdigTeamReadIBM(d, &t)
203+
var ibmPlatformMetrics *string
204+
if t.NamespaceFilters != nil {
205+
ibmPlatformMetrics = t.NamespaceFilters.IBMPlatformMetrics
206+
}
207+
_ = d.Set("enable_ibm_platform_metrics", t.CanUseBeaconMetrics)
208+
_ = d.Set("ibm_platform_metrics", ibmPlatformMetrics)
204209

205210
return nil
206211
}
@@ -288,7 +293,16 @@ func secureTeamFromResourceData(d *schema.ResourceData, clientType ClientType) v
288293
t.ZoneIDs[i] = z.(int)
289294
}
290295

291-
teamFromResourceDataIBM(d, &t)
296+
canUseBeaconMetrics := d.Get("enable_ibm_platform_metrics").(bool)
297+
t.CanUseBeaconMetrics = &canUseBeaconMetrics
298+
299+
if v, ok := d.GetOk("ibm_platform_metrics"); ok {
300+
metrics := v.(string)
301+
if t.NamespaceFilters == nil {
302+
t.NamespaceFilters = &v2.NamespaceFilters{}
303+
}
304+
t.NamespaceFilters.IBMPlatformMetrics = &metrics
305+
}
292306

293307
return t
294308
}

sysdig/resource_sysdig_team_common.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

website/docs/r/monitor_team.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "sysdig_monitor_team" "devops" {
2121
entrypoint {
2222
type = "Explore"
2323
}
24-
24+
2525
user_roles {
2626
email = data.sysdig_current_user.me.email
2727
role = "ROLE_TEAM_MANAGER"
@@ -36,8 +36,11 @@ resource "sysdig_monitor_team" "devops" {
3636
3737
role = data.sysdig_custom_role.custom_role.id
3838
}
39+
40+
filter = "kubernetes.namespace.name in (\"kube-system\") and kubernetes.deployment.name in (\"coredns\")"
41+
prometheus_remote_write_metrics_filter = "kube_cluster_name in (\"test-cluster\", \"test-k8s-data\") and kube_deployment_name = \"coredns\" and my_metric starts with \"prefix\" and not my_metric contains \"prefix-test\""
3942
}
40-
43+
4144
data "sysdig_current_user" "me" {
4245
}
4346
@@ -50,21 +53,22 @@ data "sysdig_custom_role" "custom_role" {
5053

5154
* `name` - (Required) The name of the Monitor Team. It must be unique and must not exist in Secure.
5255

53-
* `entrypoint` - (Required) Main entry point for the current team in the product.
56+
* `entrypoint` - (Required) Main entry point for the current team in the product.
5457
See the Entrypoint argument reference section for more information.
5558

5659
* `description` - (Optional) A description of the team.
5760

5861
* `theme` - (Optional) Colour of the team. Default: "#73A1F7".
5962

60-
* `scope_by` - (Optional) Scope for the team. Default: "container".
63+
* `scope_by` - (Optional) Scope for the team, either "container" or "host". Default: "container". If set to host, Team members can see all Host-level and Container-level information. If set to Container, Team members can see only Container-level information.
6164

62-
* `filter` - (Optional) If the team can only see some resources,
63-
write down a filter of such resources.
64-
65-
* `use_sysdig_capture` - (Optional) Defines if the team is able to create Sysdig Capture files.
65+
* `filter` - (Optional) Use this option to select which Agent Metrics data users of this team can view. Not setting it will allow users to see all Agent Metrics data.
66+
67+
* `prometheus_remote_write_metrics_filter` - (Optional) Use this option to select which Prometheus Remote Write data users of this team can view. Not setting it will allow users to see all Prometheus Remote Write data.
68+
69+
* `use_sysdig_capture` - (Optional) Defines if the team is able to create Sysdig Capture files.
6670
Default: true.
67-
71+
6872
* `can_see_infrastructure_events` - (Optional) TODO. Default: false.
6973

7074
* `can_use_aws_data` - (Optional) TODO. Default: false.
@@ -99,9 +103,9 @@ In addition to all arguments above, the following attributes are exported:
99103

100104
### IBM Cloud Monitoring arguments
101105

102-
* `enable_ibm_platform_metrics` - (Optional) Enable platform metrics on IBM Cloud Monitoring.
106+
* `enable_ibm_platform_metrics` - (Optional) Enable Platform Metrics on IBM Cloud Monitoring.
103107

104-
* `ibm_platform_metrics` - (Optional) Define platform metrics on IBM Cloud Monitoring.
108+
* `ibm_platform_metrics` - (Optional) Use this option to select which Platform Metrics data users of this team can view. Not setting it will allow users to see all Platform Metrics data.
105109

106110
## Import
107111

0 commit comments

Comments
 (0)