Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .tutone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1704,4 +1704,124 @@ packages:
types:
- name: EntityGuid
field_type_override: common.EntityGUID
skip_type_create: true

# - name: entitymanagement
# path: pkg/entitymanagement
# import_path: github.com/newrelic/newrelic-client-go/v2/pkg/entitymanagement
# generators:
# - typegen
# - nerdgraphclient
# imports:
# - github.com/newrelic/newrelic-client-go/v2/pkg/accounts
# - github.com/newrelic/newrelic-client-go/v2/pkg/common
# - github.com/newrelic/newrelic-client-go/v2/pkg/nrtime
# - github.com/newrelic/newrelic-client-go/v2/pkg/users
# queries:
# - path: [ "actor", "entityManagement" ]
# endpoints:
# - name: entity
# max_query_field_depth: 4
# exclude_fields:
# - agents
# - tools
# - name: entitySearch
# max_query_field_depth: 4
# exclude_fields:
# - agents
# - tools
# mutations:
# - name: entityManagementCreatePipelineCloudRule
# max_query_field_depth: 3
# - name: entityManagementDelete
# max_query_field_depth: 3
# types:
# - name: ID
# field_type_override: string
# skip_type_create: true
# - name: Nrql
# field_type_override: nrdb.NRQL
# skip_type_create: true
#
# # nrtime imports
# - name: DateTime
# field_type_override: nrtime.DateTime
# skip_type_create: true
# - name: EpochSeconds
# field_type_override: nrtime.EpochSeconds
# skip_type_create: true
# - name: EpochMilliseconds
# field_type_override: "*nrtime.EpochMilliseconds"
# skip_type_create: true
# - name: Minutes
# field_type_override: nrtime.Minutes
# skip_type_create: true
# - name: Seconds
# field_type_override: nrtime.Seconds
# skip_type_create: true

############### WARNING ###################
# The pipelinecontrol package has been generated using Tutone, but with a modified implementation in https://github.com/newrelic/tutone/pull/261
# This was done to handle the EntityManagementEntity interface and its implementations correctly, as Tutone's native implementation does not allow
# selecting a specific implementation of the interface, which is causing inclusion of all other implementations which are pretty fragile at this point.
# The implementation of Tutone in this PR allows selecting a specific implementation of an interface, using the `include_implementations` key.
# To regenerate (update via Tutone) this package, make sure the version of Tutone in the PR above is checked out to.
###########################################
- name: pipelinecontrol
path: pkg/pipelinecontrol
import_path: github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol
generators:
- typegen
- nerdgraphclient
imports:
- github.com/newrelic/newrelic-client-go/v2/pkg/accounts
- github.com/newrelic/newrelic-client-go/v2/pkg/common
- github.com/newrelic/newrelic-client-go/v2/pkg/nrtime
- github.com/newrelic/newrelic-client-go/v2/pkg/users
queries:
- path: [ "actor", "entityManagement" ]
endpoints:
- name: entity
max_query_field_depth: 4
exclude_fields:
- agents
- tools
- name: entitySearch
max_query_field_depth: 4
exclude_fields:
- agents
- tools
mutations:
- name: entityManagementCreatePipelineCloudRule
max_query_field_depth: 3
- name: entityManagementUpdatePipelineCloudRule
max_query_field_depth: 3
- name: entityManagementDelete
max_query_field_depth: 3
types:
- name: EntityManagementEntity
include_implementations:
- EntityManagementPipelineCloudRuleEntity
- name: ID
field_type_override: string
skip_type_create: true
- name: Nrql
field_type_override: nrdb.NRQL
skip_type_create: true

# nrtime imports
- name: DateTime
field_type_override: nrtime.DateTime
skip_type_create: true
- name: EpochSeconds
field_type_override: nrtime.EpochSeconds
skip_type_create: true
- name: EpochMilliseconds
field_type_override: "*nrtime.EpochMilliseconds"
skip_type_create: true
- name: Minutes
field_type_override: nrtime.Minutes
skip_type_create: true
- name: Seconds
field_type_override: nrtime.Seconds
skip_type_create: true
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/imdario/mergo v0.3.16
github.com/mitchellh/mapstructure v1.4.3
github.com/robertkrimen/otto v0.5.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80
Expand All @@ -20,7 +21,6 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/robertkrimen/otto v0.5.1 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.4.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
Expand Down
3 changes: 3 additions & 0 deletions newrelic/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/newrelic/newrelic-client-go/v2/pkg/nrdb"
"github.com/newrelic/newrelic-client-go/v2/pkg/nrqldroprules"
"github.com/newrelic/newrelic-client-go/v2/pkg/organization"
"github.com/newrelic/newrelic-client-go/v2/pkg/pipelinecontrol"
"github.com/newrelic/newrelic-client-go/v2/pkg/plugins"
"github.com/newrelic/newrelic-client-go/v2/pkg/servicelevel"
"github.com/newrelic/newrelic-client-go/v2/pkg/synthetics"
Expand Down Expand Up @@ -70,6 +71,7 @@ type NewRelic struct {
Nrdb nrdb.Nrdb
Nrqldroprules nrqldroprules.Nrqldroprules
Organization organization.Organization
Pipelinecontrol pipelinecontrol.Pipelinecontrol
Plugins plugins.Plugins
ServiceLevel servicelevel.Servicelevel
Synthetics synthetics.Synthetics
Expand Down Expand Up @@ -120,6 +122,7 @@ func New(opts ...ConfigOption) (*NewRelic, error) {
Nrdb: nrdb.New(cfg),
Nrqldroprules: nrqldroprules.New(cfg),
Organization: organization.New(cfg),
Pipelinecontrol: pipelinecontrol.New(cfg),
Plugins: plugins.New(cfg),
ServiceLevel: servicelevel.New(cfg),
Synthetics: synthetics.New(cfg),
Expand Down
151 changes: 151 additions & 0 deletions pkg/pipelinecontrol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# 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/
23 changes: 23 additions & 0 deletions pkg/pipelinecontrol/pipelinecontrol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package pipelinecontrol

import (
"github.com/newrelic/newrelic-client-go/v2/internal/http"
"github.com/newrelic/newrelic-client-go/v2/pkg/config"
"github.com/newrelic/newrelic-client-go/v2/pkg/logging"
)

type Pipelinecontrol struct {
client http.Client
logger logging.Logger
config config.Config
}

func New(config config.Config) Pipelinecontrol {
client := http.NewClient(config)
pkg := Pipelinecontrol{
client: client,
logger: config.GetLogger(),
config: config,
}
return pkg
}
Loading
Loading