Skip to content

Conversation

@pranav-new-relic
Copy link
Member

@pranav-new-relic pranav-new-relic commented Sep 1, 2025

This PR aims at adding a brand new pipelinecontrol package to the New Relic Go Client, which currently serves the purpose of helping customers manage Pipeline Cloud Rules (that shall be replacing NRQL Drop Rules, owing to an upcoming EOL).

See the contents of the package attached below, for more details.

# pipelinecontrol
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.
- Create rules: define NRQL-based drop filters.
- Get rules: fetch full details of the pipeline cloud rule entity, and metadata.
- Update rules: change name, description, or NRQL.
- Delete rules: remove entities by ID.
## ⚠️ Important: NRQL Drop Rules Deprecation Notice and Upcoming EOL
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.
## Install
```go
import "github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol"
```
## Create a client
```go
package main
import (
"github.com/newrelic/newrelic-client-go/v2/pkg/config"
"github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol"
)
func main() {
cfg := config.New()
cfg.PersonalAPIKey = "YOUR_API_KEY"
// Optional: cfg.Region = "EU" // default is US
client := pipelinecontrol.New(cfg)
_ = client
}
```
## Key types
- `EntityManagementPipelineCloudRuleEntityCreateInput`
- `EntityManagementPipelineCloudRuleEntityUpdateInput`
- `EntityManagementScopedReferenceInput`
- `EntityManagementPipelineCloudRuleEntity`
- `EntityManagementEntityInterface`
Note: For NRQL values, use the `nrdb.NRQL` type when setting NRQL on inputs.
## Imports used in examples
```go
import (
"fmt"
"log"
"github.com/newrelic/newrelic-client-go/v2/pkg/nrdb"
"github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol"
)
```
## Create a rule (`EntityManagementCreatePipelineCloudRule`)
Purpose: Create a Pipeline Cloud Rule with a name, description, NRQL, and scope.
```go
func createRule() {
// assume client created
createInput := pipelinecontrol.EntityManagementPipelineCloudRuleEntityCreateInput{
Name: "drop-debug-logs",
Description: "Drop DEBUG logs in production",
NRQL: nrdb.NRQL("DELETE FROM Log WHERE logLevel = 'DEBUG' AND environment = 'production'"),
Scope: pipelinecontrol.EntityManagementScopedReferenceInput{
Type: pipelinecontrol.EntityManagementEntityScopeTypes.ACCOUNT,
ID: "YOUR_ACCOUNT_ID",
},
}
result, err := client.EntityManagementCreatePipelineCloudRule(createInput)
if err != nil {
log.Fatalf("create failed: %v", err)
}
fmt.Printf("Created rule: id=%s name=%s version=%d\n",
result.Entity.ID, result.Entity.Name, result.Entity.Metadata.Version)
}
```
## Get a rule (`GetEntity`)
Purpose: Fetch the entity and access typed fields on a Pipeline Cloud Rule.
```go
func getRule(id string) {
entity, err := client.GetEntity(id)
if err != nil {
log.Fatalf("get failed: %v", err)
}
rule, ok := (*entity).(*pipelinecontrol.EntityManagementPipelineCloudRuleEntity)
if !ok {
log.Fatalf("entity %s is not a PipelineCloudRuleEntity", id)
}
fmt.Printf("Rule: id=%s name=%s version=%d\n", rule.ID, rule.Name, rule.Metadata.Version)
fmt.Printf("NRQL: %s\n", rule.NRQL)
}
```
## Update a rule (`EntityManagementUpdatePipelineCloudRule`)
Purpose: Change name, description, or NRQL. The API handles versioning internally.
```go
func updateRule(id string) {
updateInput := pipelinecontrol.EntityManagementPipelineCloudRuleEntityUpdateInput{
Name: "drop-debug-logs-updated",
Description: "Drop DEBUG logs everywhere",
NRQL: nrdb.NRQL("DELETE FROM Log WHERE logLevel = 'DEBUG'"),
}
result, err := client.EntityManagementUpdatePipelineCloudRule(id, updateInput)
if err != nil {
log.Fatalf("update failed: %v", err)
}
fmt.Printf("Updated rule: id=%s name=%s version=%d\n",
result.Entity.ID, result.Entity.Name, result.Entity.Metadata.Version)
}
```
## Delete a rule (`EntityManagementDelete`)
Purpose: Remove an entity by ID.
```go
func deleteRule(id string) {
del, err := client.EntityManagementDelete(id)
if err != nil {
log.Fatalf("delete failed: %v", err)
}
fmt.Printf("Deleted entity id=%s\n", del.ID)
}
```
## Common NRQL snippets
- Drop health checks: `DELETE FROM Log WHERE uri LIKE '%/health%'`
- Drop verbose levels: `DELETE FROM Log WHERE logLevel IN ('DEBUG','TRACE')`
## Links
Pipeline Cloud Rules references:
- https://docs.newrelic.com/docs/new-relic-control/pipeline-control/cloud-rules-api/
- https://docs.newrelic.com/docs/new-relic-control/pipeline-control/create-pipeline-rules/

FYI: replaces #1326

@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2025

Codecov Report

❌ Patch coverage is 70.78652% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.03%. Comparing base (279e464) to head (50e4d9c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/pipelinecontrol/pipelinecontrol_api.go 67.50% 23 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1330      +/-   ##
==========================================
+ Coverage   35.63%   36.03%   +0.39%     
==========================================
  Files         133      135       +2     
  Lines        7871     7960      +89     
==========================================
+ Hits         2805     2868      +63     
- Misses       4870     4893      +23     
- Partials      196      199       +3     
Flag Coverage Δ
unit 36.03% <70.78%> (+0.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pranav-new-relic pranav-new-relic merged commit f50e85c into main Sep 1, 2025
14 of 17 checks passed
@pranav-new-relic pranav-new-relic deleted the NR-442625-v2 branch September 1, 2025 11:13
msivant pushed a commit to msivant/newrelic-client-go that referenced this pull request Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants