Skip to content

Commit 69c1d0c

Browse files
pranav-new-relicmsivant
authored andcommitted
feat(pipelinecontrol): add a new Pipeline Control package to the client (newrelic#1330)
1 parent 1d446a4 commit 69c1d0c

File tree

10 files changed

+10362
-1
lines changed

10 files changed

+10362
-1
lines changed

.tutone.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,4 +1704,124 @@ packages:
17041704
types:
17051705
- name: EntityGuid
17061706
field_type_override: common.EntityGUID
1707+
skip_type_create: true
1708+
1709+
# - name: entitymanagement
1710+
# path: pkg/entitymanagement
1711+
# import_path: github.com/newrelic/newrelic-client-go/v2/pkg/entitymanagement
1712+
# generators:
1713+
# - typegen
1714+
# - nerdgraphclient
1715+
# imports:
1716+
# - github.com/newrelic/newrelic-client-go/v2/pkg/accounts
1717+
# - github.com/newrelic/newrelic-client-go/v2/pkg/common
1718+
# - github.com/newrelic/newrelic-client-go/v2/pkg/nrtime
1719+
# - github.com/newrelic/newrelic-client-go/v2/pkg/users
1720+
# queries:
1721+
# - path: [ "actor", "entityManagement" ]
1722+
# endpoints:
1723+
# - name: entity
1724+
# max_query_field_depth: 4
1725+
# exclude_fields:
1726+
# - agents
1727+
# - tools
1728+
# - name: entitySearch
1729+
# max_query_field_depth: 4
1730+
# exclude_fields:
1731+
# - agents
1732+
# - tools
1733+
# mutations:
1734+
# - name: entityManagementCreatePipelineCloudRule
1735+
# max_query_field_depth: 3
1736+
# - name: entityManagementDelete
1737+
# max_query_field_depth: 3
1738+
# types:
1739+
# - name: ID
1740+
# field_type_override: string
1741+
# skip_type_create: true
1742+
# - name: Nrql
1743+
# field_type_override: nrdb.NRQL
1744+
# skip_type_create: true
1745+
#
1746+
# # nrtime imports
1747+
# - name: DateTime
1748+
# field_type_override: nrtime.DateTime
1749+
# skip_type_create: true
1750+
# - name: EpochSeconds
1751+
# field_type_override: nrtime.EpochSeconds
1752+
# skip_type_create: true
1753+
# - name: EpochMilliseconds
1754+
# field_type_override: "*nrtime.EpochMilliseconds"
1755+
# skip_type_create: true
1756+
# - name: Minutes
1757+
# field_type_override: nrtime.Minutes
1758+
# skip_type_create: true
1759+
# - name: Seconds
1760+
# field_type_override: nrtime.Seconds
1761+
# skip_type_create: true
1762+
1763+
############### WARNING ###################
1764+
# The pipelinecontrol package has been generated using Tutone, but with a modified implementation in https://github.com/newrelic/tutone/pull/261
1765+
# This was done to handle the EntityManagementEntity interface and its implementations correctly, as Tutone's native implementation does not allow
1766+
# selecting a specific implementation of the interface, which is causing inclusion of all other implementations which are pretty fragile at this point.
1767+
# The implementation of Tutone in this PR allows selecting a specific implementation of an interface, using the `include_implementations` key.
1768+
# To regenerate (update via Tutone) this package, make sure the version of Tutone in the PR above is checked out to.
1769+
###########################################
1770+
- name: pipelinecontrol
1771+
path: pkg/pipelinecontrol
1772+
import_path: github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol
1773+
generators:
1774+
- typegen
1775+
- nerdgraphclient
1776+
imports:
1777+
- github.com/newrelic/newrelic-client-go/v2/pkg/accounts
1778+
- github.com/newrelic/newrelic-client-go/v2/pkg/common
1779+
- github.com/newrelic/newrelic-client-go/v2/pkg/nrtime
1780+
- github.com/newrelic/newrelic-client-go/v2/pkg/users
1781+
queries:
1782+
- path: [ "actor", "entityManagement" ]
1783+
endpoints:
1784+
- name: entity
1785+
max_query_field_depth: 4
1786+
exclude_fields:
1787+
- agents
1788+
- tools
1789+
- name: entitySearch
1790+
max_query_field_depth: 4
1791+
exclude_fields:
1792+
- agents
1793+
- tools
1794+
mutations:
1795+
- name: entityManagementCreatePipelineCloudRule
1796+
max_query_field_depth: 3
1797+
- name: entityManagementUpdatePipelineCloudRule
1798+
max_query_field_depth: 3
1799+
- name: entityManagementDelete
1800+
max_query_field_depth: 3
1801+
types:
1802+
- name: EntityManagementEntity
1803+
include_implementations:
1804+
- EntityManagementPipelineCloudRuleEntity
1805+
- name: ID
1806+
field_type_override: string
1807+
skip_type_create: true
1808+
- name: Nrql
1809+
field_type_override: nrdb.NRQL
1810+
skip_type_create: true
1811+
1812+
# nrtime imports
1813+
- name: DateTime
1814+
field_type_override: nrtime.DateTime
1815+
skip_type_create: true
1816+
- name: EpochSeconds
1817+
field_type_override: nrtime.EpochSeconds
1818+
skip_type_create: true
1819+
- name: EpochMilliseconds
1820+
field_type_override: "*nrtime.EpochMilliseconds"
1821+
skip_type_create: true
1822+
- name: Minutes
1823+
field_type_override: nrtime.Minutes
1824+
skip_type_create: true
1825+
- name: Seconds
1826+
field_type_override: nrtime.Seconds
17071827
skip_type_create: true

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/hashicorp/go-retryablehttp v0.7.7
99
github.com/imdario/mergo v0.3.16
1010
github.com/mitchellh/mapstructure v1.4.3
11+
github.com/robertkrimen/otto v0.5.1
1112
github.com/sirupsen/logrus v1.9.3
1213
github.com/stretchr/testify v1.9.0
1314
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80
@@ -20,7 +21,6 @@ require (
2021
github.com/kr/text v0.2.0 // indirect
2122
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
2223
github.com/pmezard/go-difflib v1.0.0 // indirect
23-
github.com/robertkrimen/otto v0.5.1 // indirect
2424
golang.org/x/sys v0.20.0 // indirect
2525
golang.org/x/text v0.4.0 // indirect
2626
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect

newrelic/newrelic.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/newrelic/newrelic-client-go/v2/pkg/nrdb"
3636
"github.com/newrelic/newrelic-client-go/v2/pkg/nrqldroprules"
3737
"github.com/newrelic/newrelic-client-go/v2/pkg/organization"
38+
"github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol"
3839
"github.com/newrelic/newrelic-client-go/v2/pkg/plugins"
3940
"github.com/newrelic/newrelic-client-go/v2/pkg/servicelevel"
4041
"github.com/newrelic/newrelic-client-go/v2/pkg/synthetics"
@@ -70,6 +71,7 @@ type NewRelic struct {
7071
Nrdb nrdb.Nrdb
7172
Nrqldroprules nrqldroprules.Nrqldroprules
7273
Organization organization.Organization
74+
Pipelinecontrol pipelinecontrol.Pipelinecontrol
7375
Plugins plugins.Plugins
7476
ServiceLevel servicelevel.Servicelevel
7577
Synthetics synthetics.Synthetics
@@ -120,6 +122,7 @@ func New(opts ...ConfigOption) (*NewRelic, error) {
120122
Nrdb: nrdb.New(cfg),
121123
Nrqldroprules: nrqldroprules.New(cfg),
122124
Organization: organization.New(cfg),
125+
Pipelinecontrol: pipelinecontrol.New(cfg),
123126
Plugins: plugins.New(cfg),
124127
ServiceLevel: servicelevel.New(cfg),
125128
Synthetics: synthetics.New(cfg),

pkg/pipelinecontrol/README.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package pipelinecontrol
2+
3+
import (
4+
"github.com/newrelic/newrelic-client-go/v2/internal/http"
5+
"github.com/newrelic/newrelic-client-go/v2/pkg/config"
6+
"github.com/newrelic/newrelic-client-go/v2/pkg/logging"
7+
)
8+
9+
type Pipelinecontrol struct {
10+
client http.Client
11+
logger logging.Logger
12+
config config.Config
13+
}
14+
15+
func New(config config.Config) Pipelinecontrol {
16+
client := http.NewClient(config)
17+
pkg := Pipelinecontrol{
18+
client: client,
19+
logger: config.GetLogger(),
20+
config: config,
21+
}
22+
return pkg
23+
}

0 commit comments

Comments
 (0)