|
| 1 | +# pipelinecontrol |
| 2 | + |
| 3 | +The `pipelinecontrol` package is a collection of functions in Go, used to manage resources in New Relic associated with Pipeline Control. Currently, this package supports managing Pipeline Cloud Rules via New Relic’s Entity Management API. It lets you create, read, update, delete pipeline cloud rules that process inbound telemetry (for example, drop logs) using NRQL. |
| 4 | + |
| 5 | +- Create rules: define NRQL-based drop filters. |
| 6 | +- Get rules: fetch full details of the pipeline cloud rule entity, and metadata. |
| 7 | +- Update rules: change name, description, or NRQL. |
| 8 | +- Delete rules: remove entities by ID. |
| 9 | + |
| 10 | +## ⚠️ Important: NRQL Drop Rules Deprecation Notice and Upcoming EOL |
| 11 | + |
| 12 | +NRQL Drop Rules are being deprecated and will reach their end-of-life on January 7, 2026; these shall be replaced by Pipeline Cloud Rules. If you manage your droprules via the New Relic Go Client `nrqldroprules` package, we recommend migrating your scripts using functions in `nrqldroprules` to the functions described in this package as soon as possible to ensure uninterrupted service and to take advantage of the new capabilities. These new Pipeline Cloud Rules provide enhanced functionality for managing telemetry data processing with improved performance and reliability. |
| 13 | + |
| 14 | +## Install |
| 15 | + |
| 16 | +```go |
| 17 | +import "github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol" |
| 18 | +``` |
| 19 | + |
| 20 | +## Create a client |
| 21 | + |
| 22 | +```go |
| 23 | +package main |
| 24 | + |
| 25 | +import ( |
| 26 | + "github.com/newrelic/newrelic-client-go/v2/pkg/config" |
| 27 | + "github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol" |
| 28 | +) |
| 29 | + |
| 30 | +func main() { |
| 31 | + cfg := config.New() |
| 32 | + cfg.PersonalAPIKey = "YOUR_API_KEY" |
| 33 | + // Optional: cfg.Region = "EU" // default is US |
| 34 | + |
| 35 | + client := pipelinecontrol.New(cfg) |
| 36 | + _ = client |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +## Key types |
| 41 | + |
| 42 | +- `EntityManagementPipelineCloudRuleEntityCreateInput` |
| 43 | +- `EntityManagementPipelineCloudRuleEntityUpdateInput` |
| 44 | +- `EntityManagementScopedReferenceInput` |
| 45 | +- `EntityManagementPipelineCloudRuleEntity` |
| 46 | +- `EntityManagementEntityInterface` |
| 47 | + |
| 48 | +Note: For NRQL values, use the `nrdb.NRQL` type when setting NRQL on inputs. |
| 49 | + |
| 50 | +## Imports used in examples |
| 51 | + |
| 52 | +```go |
| 53 | +import ( |
| 54 | + "fmt" |
| 55 | + "log" |
| 56 | + |
| 57 | + "github.com/newrelic/newrelic-client-go/v2/pkg/nrdb" |
| 58 | + "github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol" |
| 59 | +) |
| 60 | +``` |
| 61 | + |
| 62 | +## Create a rule (`EntityManagementCreatePipelineCloudRule`) |
| 63 | + |
| 64 | +Purpose: Create a Pipeline Cloud Rule with a name, description, NRQL, and scope. |
| 65 | + |
| 66 | +```go |
| 67 | +func createRule() { |
| 68 | + // assume client created |
| 69 | + createInput := pipelinecontrol.EntityManagementPipelineCloudRuleEntityCreateInput{ |
| 70 | + Name: "drop-debug-logs", |
| 71 | + Description: "Drop DEBUG logs in production", |
| 72 | + NRQL: nrdb.NRQL("DELETE FROM Log WHERE logLevel = 'DEBUG' AND environment = 'production'"), |
| 73 | + Scope: pipelinecontrol.EntityManagementScopedReferenceInput{ |
| 74 | + Type: pipelinecontrol.EntityManagementEntityScopeTypes.ACCOUNT, |
| 75 | + ID: "YOUR_ACCOUNT_ID", |
| 76 | + }, |
| 77 | + } |
| 78 | + |
| 79 | + result, err := client.EntityManagementCreatePipelineCloudRule(createInput) |
| 80 | + if err != nil { |
| 81 | + log.Fatalf("create failed: %v", err) |
| 82 | + } |
| 83 | + |
| 84 | + fmt.Printf("Created rule: id=%s name=%s version=%d\n", |
| 85 | + result.Entity.ID, result.Entity.Name, result.Entity.Metadata.Version) |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +## Get a rule (`GetEntity`) |
| 90 | + |
| 91 | +Purpose: Fetch the entity and access typed fields on a Pipeline Cloud Rule. |
| 92 | + |
| 93 | +```go |
| 94 | +func getRule(id string) { |
| 95 | + entity, err := client.GetEntity(id) |
| 96 | + if err != nil { |
| 97 | + log.Fatalf("get failed: %v", err) |
| 98 | + } |
| 99 | + rule, ok := (*entity).(*pipelinecontrol.EntityManagementPipelineCloudRuleEntity) |
| 100 | + if !ok { |
| 101 | + log.Fatalf("entity %s is not a PipelineCloudRuleEntity", id) |
| 102 | + } |
| 103 | + fmt.Printf("Rule: id=%s name=%s version=%d\n", rule.ID, rule.Name, rule.Metadata.Version) |
| 104 | + fmt.Printf("NRQL: %s\n", rule.NRQL) |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +## Update a rule (`EntityManagementUpdatePipelineCloudRule`) |
| 109 | + |
| 110 | +Purpose: Change name, description, or NRQL. The API handles versioning internally. |
| 111 | + |
| 112 | +```go |
| 113 | +func updateRule(id string) { |
| 114 | + updateInput := pipelinecontrol.EntityManagementPipelineCloudRuleEntityUpdateInput{ |
| 115 | + Name: "drop-debug-logs-updated", |
| 116 | + Description: "Drop DEBUG logs everywhere", |
| 117 | + NRQL: nrdb.NRQL("DELETE FROM Log WHERE logLevel = 'DEBUG'"), |
| 118 | + } |
| 119 | + result, err := client.EntityManagementUpdatePipelineCloudRule(id, updateInput) |
| 120 | + if err != nil { |
| 121 | + log.Fatalf("update failed: %v", err) |
| 122 | + } |
| 123 | + fmt.Printf("Updated rule: id=%s name=%s version=%d\n", |
| 124 | + result.Entity.ID, result.Entity.Name, result.Entity.Metadata.Version) |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +## Delete a rule (`EntityManagementDelete`) |
| 129 | + |
| 130 | +Purpose: Remove an entity by ID. |
| 131 | + |
| 132 | +```go |
| 133 | +func deleteRule(id string) { |
| 134 | + del, err := client.EntityManagementDelete(id) |
| 135 | + if err != nil { |
| 136 | + log.Fatalf("delete failed: %v", err) |
| 137 | + } |
| 138 | + fmt.Printf("Deleted entity id=%s\n", del.ID) |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +## Common NRQL snippets |
| 143 | + |
| 144 | +- Drop health checks: `DELETE FROM Log WHERE uri LIKE '%/health%'` |
| 145 | +- Drop verbose levels: `DELETE FROM Log WHERE logLevel IN ('DEBUG','TRACE')` |
| 146 | + |
| 147 | +## Links |
| 148 | + |
| 149 | +Pipeline Cloud Rules references: |
| 150 | +- https://docs.newrelic.com/docs/new-relic-control/pipeline-control/cloud-rules-api/ |
| 151 | +- https://docs.newrelic.com/docs/new-relic-control/pipeline-control/create-pipeline-rules/ |
0 commit comments