nrdb

package
v2.44.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2024 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Overview

Package nrdb provides a programmatic API for interacting with the New Relic Database. It can be used to run freeform NRQL queries. Details on how to use the New Relic Query Language are available here:

https://docs.newrelic.com/docs/query-data/nrql-new-relic-query-language/getting-started/introduction-nrql

Authentication

You will need a valid Personal API key to communicate with the backend New Relic API that provides this functionality. See the API key documentation below for more information on how to locate this key:

https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

Package nrdb provides a programmatic API for interacting with NRDB, New Relic's Datastore

Code generated by tutone: DO NOT EDIT

Example (Query)
// Initialize the client configuration.  A Personal API key is required to
// communicate with the backend API.
cfg := config.New()
cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY")

accountID, err := strconv.Atoi(os.Getenv("NEW_RELIC_ACCOUNT_ID"))
if err != nil {
	log.Fatal("example requires NEW_RELIC_ACCONT_ID to be set, got error: ", err)
}

// Initialize the client.
client := New(cfg)

// Execute a NRQL query to retrieve the average duration of transactions for
// the "Example application" app.
query := NRQL("SELECT average(duration) FROM Transaction TIMESERIES WHERE appName = 'Example application'")

resp, err := client.Query(accountID, query)
if err != nil {
	log.Fatal("error running NerdGraph query: ", err)
}

var durations []float64
for _, r := range resp.Results {
	durations = append(durations, r["average.duration"].(float64))
}

// Output the raw time series values for transaction duration.
fmt.Printf("durations: %v\n", durations)
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var ChartFormatTypeTypes = struct {
	PDF ChartFormatType
	PNG ChartFormatType
}{
	PDF: "PDF",
	PNG: "PNG",
}
View Source
var ChartImageTypeTypes = struct {
	APDEX                  ChartImageType
	AREA                   ChartImageType
	BAR                    ChartImageType
	BASELINE               ChartImageType
	BILLBOARD              ChartImageType
	BULLET                 ChartImageType
	EVENT_FEED             ChartImageType
	FUNNEL                 ChartImageType
	HEATMAP                ChartImageType
	HISTOGRAM              ChartImageType
	LINE                   ChartImageType
	PIE                    ChartImageType
	SCATTER                ChartImageType
	STACKED_HORIZONTAL_BAR ChartImageType
	TABLE                  ChartImageType
	VERTICAL_BAR           ChartImageType
}{
	APDEX:                  "APDEX",
	AREA:                   "AREA",
	BAR:                    "BAR",
	BASELINE:               "BASELINE",
	BILLBOARD:              "BILLBOARD",
	BULLET:                 "BULLET",
	EVENT_FEED:             "EVENT_FEED",
	FUNNEL:                 "FUNNEL",
	HEATMAP:                "HEATMAP",
	HISTOGRAM:              "HISTOGRAM",
	LINE:                   "LINE",
	PIE:                    "PIE",
	SCATTER:                "SCATTER",
	STACKED_HORIZONTAL_BAR: "STACKED_HORIZONTAL_BAR",
	TABLE:                  "TABLE",
	VERTICAL_BAR:           "VERTICAL_BAR",
}
View Source
var EmbeddedChartTypeTypes = struct {
	APDEX                  EmbeddedChartType
	AREA                   EmbeddedChartType
	BAR                    EmbeddedChartType
	BASELINE               EmbeddedChartType
	BILLBOARD              EmbeddedChartType
	BULLET                 EmbeddedChartType
	EMPTY                  EmbeddedChartType
	EVENT_FEED             EmbeddedChartType
	FUNNEL                 EmbeddedChartType
	HEATMAP                EmbeddedChartType
	HISTOGRAM              EmbeddedChartType
	JSON                   EmbeddedChartType
	LINE                   EmbeddedChartType
	MARKDOWN               EmbeddedChartType
	PIE                    EmbeddedChartType
	SCATTER                EmbeddedChartType
	STACKED_HORIZONTAL_BAR EmbeddedChartType
	TABLE                  EmbeddedChartType
	TRAFFIC_LIGHT          EmbeddedChartType
	VERTICAL_BAR           EmbeddedChartType
}{
	APDEX:                  "APDEX",
	AREA:                   "AREA",
	BAR:                    "BAR",
	BASELINE:               "BASELINE",
	BILLBOARD:              "BILLBOARD",
	BULLET:                 "BULLET",
	EMPTY:                  "EMPTY",
	EVENT_FEED:             "EVENT_FEED",
	FUNNEL:                 "FUNNEL",
	HEATMAP:                "HEATMAP",
	HISTOGRAM:              "HISTOGRAM",
	JSON:                   "JSON",
	LINE:                   "LINE",
	MARKDOWN:               "MARKDOWN",
	PIE:                    "PIE",
	SCATTER:                "SCATTER",
	STACKED_HORIZONTAL_BAR: "STACKED_HORIZONTAL_BAR",
	TABLE:                  "TABLE",
	TRAFFIC_LIGHT:          "TRAFFIC_LIGHT",
	VERTICAL_BAR:           "VERTICAL_BAR",
}

Functions

This section is empty.

Types

type ChartFormatType

type ChartFormatType string

ChartFormatType - Represents all the format types available for static charts.

type ChartImageType

type ChartImageType string

ChartImageType - Represents all the visualization types available for static charts.

type EmbeddedChartType

type EmbeddedChartType string

EmbeddedChartType - Represents all the visualization types available for embedded charts.

type EventAttributeDefinition

type EventAttributeDefinition struct {
	// This attribute's category
	Category string `json:"category,omitempty"`
	// A short description of this attribute
	Definition string `json:"definition,omitempty"`
	// The New Relic docs page for this attribute
	DocumentationURL string `json:"documentationUrl,omitempty"`
	// The human-friendly formatted name of the attribute
	Label string `json:"label,omitempty"`
	// The name of the attribute
	Name string `json:"name,omitempty"`
}

EventAttributeDefinition - A human-readable definition of an NRDB Event Type Attribute

type EventDefinition

type EventDefinition struct {
	// A list of attribute definitions for this event type
	Attributes []EventAttributeDefinition `json:"attributes,omitempty"`
	// A short description of this event
	Definition string `json:"definition,omitempty"`
	// The human-friendly formatted name of the event
	Label string `json:"label,omitempty"`
	// The name of the event
	Name string `json:"name,omitempty"`
}

EventDefinition - A human-readable definition of an NRDB Event Type

type ID added in v2.27.0

type ID string

ID - The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.

type NRDBMetadata

type NRDBMetadata struct {
	// A list of the event types that were queried.
	EventTypes []string `json:"eventTypes,omitempty"`
	// A list of facets that were queried.
	Facets []string `json:"facets,omitempty"`
	// Messages from NRDB included with the result.
	Messages []string `json:"messages,omitempty"`
	// Details about the query time window.
	TimeWindow NRDBMetadataTimeWindow `json:"timeWindow,omitempty"`
}

NRDBMetadata - An object containing metadata about the query and result.

type NRDBMetadataTimeWindow

type NRDBMetadataTimeWindow struct {
	// Timestamp marking the query begin time.
	Begin nrtime.EpochMilliseconds `json:"begin,omitempty"`
	// A clause representing the comparison time window.
	CompareWith string `json:"compareWith,omitempty"`
	// Timestamp marking the query end time.
	End nrtime.EpochMilliseconds `json:"end,omitempty"`
	// SINCE clause resulting from the query
	Since string `json:"since,omitempty"`
	// UNTIL clause resulting from the query
	Until string `json:"until,omitempty"`
}

NRDBMetadataTimeWindow - An object representing details about a query's time window.

type NRDBQueryProgress added in v2.27.0

type NRDBQueryProgress struct {
	// Whether the query has finished executing.
	Completed bool `json:"completed,omitempty"`
	// A token for retrieving the results of a previously executed asynchronous query.
	QueryId int `json:"queryId,omitempty"`
	// Results of the completed query will expire permanently after this long.
	ResultExpiration Seconds `json:"resultExpiration,omitempty"`
	// Wait at least this long before querying for completed results with the `queryId`.
	RetryAfter Seconds `json:"retryAfter,omitempty"`
	// The server may cancel the NRDB query after this long if no GraphQL queries have been made to check the `queryId`'s status.
	RetryDeadline Seconds `json:"retryDeadline,omitempty"`
}

NRDBQueryProgress - An object containing metadata about the execution of an asynchronous NRQL query.

type NRDBRawResults added in v2.27.0

type NRDBRawResults map[string]interface{}

NRDBRawResults - This scalar represents the raw nrql query results as returned from NRDB. It is a `Map` of `String` keys to values.

The shape of these objects reflect the query used to generate them, the contents of the objects is not part of the GraphQL schema.

type NRDBResult

type NRDBResult map[string]interface{}

NRDBResult - This scalar represents a NRDB Result. It is a `Map` of `String` keys to values.

The shape of these objects reflect the query used to generate them, the contents of the objects is not part of the GraphQL schema.

type NRDBResultContainer

type NRDBResultContainer struct {
	// In a `COMPARE WITH` query, the `currentResults` contain the results for the current comparison time window.
	CurrentResults []NRDBResult `json:"currentResults,omitempty"`
	// Generate a publicly sharable Embedded Chart URL for the NRQL query.
	//
	// For more details, see [our docs](https://docs.newrelic.com/docs/apis/graphql-api/tutorials/query-nrql-through-new-relic-graphql-api#embeddable-charts).
	EmbeddedChartURL string `json:"embeddedChartUrl,omitempty"`
	// Retrieve a list of event type definitions, providing descriptions
	// of the event types returned by this query, as well as details
	// of their attributes.
	EventDefinitions []EventDefinition `json:"eventDefinitions,omitempty"`
	// Metadata about the query and result.
	Metadata NRDBMetadata `json:"metadata,omitempty"`
	// The [NRQL](https://docs.newrelic.com/docs/insights/nrql-new-relic-query-language/nrql-resources/nrql-syntax-components-functions) query that was executed to yield these results.
	NRQL NRQL `json:"nrql,omitempty"`
	// In a `FACET` query, the `otherResult` contains the aggregates representing the events _not_
	// contained in an individual `results` facet.
	OtherResult NRDBResult `json:"otherResult,omitempty"`
	// In a `COMPARE WITH` query, the `previousResults` contain the results for the previous comparison time window.
	PreviousResults []NRDBResult `json:"previousResults,omitempty"`
	// Metadata about the execution of an asynchronous NRQL query.
	QueryProgress NRDBQueryProgress `json:"queryProgress,omitempty"`
	// The raw query results exactly as they are returned from NRDB. NerdGraph provides no additional transformation.
	RawResponse NRDBRawResults `json:"rawResponse,omitempty"`
	// The query results. This is a flat list of objects who's structure matches the query submitted.
	Results []NRDBResult `json:"results,omitempty"`
	// Generate a publicly sharable static chart URL for the NRQL query.
	StaticChartURL string `json:"staticChartUrl,omitempty"`
	// Retrieve a list of suggested NRQL facets for this NRDB query, to be used with
	// the `FACET` keyword in NRQL.
	//
	// Results are based on historical query behaviors.
	//
	// If the query already has a `FACET` clause, it will be ignored for the purposes
	// of suggesting facets.
	//
	// For more details, see [our docs](https://docs.newrelic.com/docs/apis/graphql-api/tutorials/nerdgraph-graphiql-nrql-tutorial#suggest-facets).
	SuggestedFacets []NRQLFacetSuggestion `json:"suggestedFacets,omitempty"`
	// Suggested queries that could help explain an anomaly in your timeseries based on either statistical differences in the data or historical usage.
	//
	// If no `anomalyTimeWindow` is supplied, we will attempt to detect a spike in the NRQL results. If no spike is found, the suggested query results will be empty.
	//
	// Input NRQL must be a TIMESERIES query and must have exactly one result.
	SuggestedQueries SuggestedNRQLQueryResponse `json:"suggestedQueries,omitempty"`
	// In a `FACET` query, the `totalResult` contains the aggregates representing _all_ the events,
	// whether or not they are contained in an individual `results` facet.
	TotalResult NRDBResult `json:"totalResult,omitempty"`
}

NRDBResultContainer - A data structure that contains the results of the NRDB query along with other capabilities that enhance those results.

Direct query results are available through `results`, `totalResult` and `otherResult`. The query you made is accessible through `nrql`, along with `metadata` about the query itself. Enhanced capabilities include `eventDefinitions`, `suggestedFacets` and more.

type NRQL

type NRQL string

NRQL - This scalar represents a NRQL query string.

See the [NRQL Docs](https://docs.newrelic.com/docs/insights/nrql-new-relic-query-language/nrql-resources/nrql-syntax-components-functions) for more information about NRQL syntax.

type NRQLFacetSuggestion

type NRQLFacetSuggestion struct {
	// A list of attribute names comprising the suggested facet.
	//
	// Raw attribute names will be returned here. Attribute names may need to be
	// backtick-quoted before inclusion in a NRQL query.
	Attributes []string `json:"attributes,omitempty"`
	// A modified version of the input NRQL, with a `FACET ...` clause appended.
	// If the original NRQL had a `FACET` clause already, it will be replaced.
	NRQL NRQL `json:"nrql,omitempty"`
}

NRQLFacetSuggestion - A suggested NRQL facet. Facet suggestions may be either a single attribute, or a list of attributes in the case of multi-attribute facet suggestions.

type NRQLHistoricalQuery

type NRQLHistoricalQuery struct {
	// The Account ID queried.
	AccountIDs []int `json:"accountIds,omitempty"`
	// The NRQL query executed.
	Query NRQL `json:"query,omitempty"`
	// The time the query was executed.
	CreatedAt nrtime.DateTime `json:"createdAt,omitempty"`
}

NRQLHistoricalQuery - An NRQL query executed in the past.

type Nrdb

type Nrdb struct {
	// contains filtered or unexported fields
}

Nrdb is used to communicate with the New Relic's Datastore, NRDB.

func New

func New(config config.Config) Nrdb

New returns a new GraphQL client for interacting with New Relic's Datastore

func (*Nrdb) Query

func (n *Nrdb) Query(accountID int, query NRQL) (*NRDBResultContainer, error)

Query facilitates making an NRQL query using NerdGraph.

func (*Nrdb) QueryHistory

func (n *Nrdb) QueryHistory() (*[]NRQLHistoricalQuery, error)

func (*Nrdb) QueryHistoryWithContext

func (n *Nrdb) QueryHistoryWithContext(ctx context.Context) (*[]NRQLHistoricalQuery, error)

func (*Nrdb) QueryWithAdditionalOptions added in v2.27.0

func (n *Nrdb) QueryWithAdditionalOptions(
	accountID int,
	query NRQL,
	timeout Seconds,
	async bool,
) (*NRDBResultContainer, error)

func (*Nrdb) QueryWithAdditionalOptionsWithContext added in v2.27.0

func (n *Nrdb) QueryWithAdditionalOptionsWithContext(
	ctx context.Context,
	accountID int,
	query NRQL,
	timeout Seconds,
	async bool,
) (*NRDBResultContainer, error)

QueryWithAdditionalOptionsWithContext facilitates making a NRQL query with the specification of a timeout between 5 and 120 seconds.

func (*Nrdb) QueryWithContext

func (n *Nrdb) QueryWithContext(ctx context.Context, accountID int, query NRQL) (*NRDBResultContainer, error)

QueryWithContext facilitates making a NRQL query.

func (*Nrdb) QueryWithExtendedResponse added in v2.34.0

func (n *Nrdb) QueryWithExtendedResponse(accountID int, query NRQL) (*NRDBResultContainer, error)

func (*Nrdb) QueryWithExtendedResponseWithContext added in v2.34.0

func (n *Nrdb) QueryWithExtendedResponseWithContext(ctx context.Context, accountID int, query NRQL) (*NRDBResultContainer, error)

QueryWithExtendedResponseWithContext facilitates making a NRQL query with additional options.

type Seconds added in v2.27.0

type Seconds int

Seconds - The `Seconds` scalar represents a duration in seconds

type SuggestedAnomalyBasedNRQLQuery

type SuggestedAnomalyBasedNRQLQuery struct {
	// Information about the anomaly upon which this suggestion is based
	Anomaly SuggestedNRQLQueryAnomaly `json:"anomaly"`
	// The NRQL string to run for the suggested query
	NRQL string `json:"nrql"`
	// A human-readable title describing what the query shows
	Title string `json:"title"`
}

SuggestedAnomalyBasedNRQLQuery - A query suggestion based on analysis of events within a specific anomalous time range vs. nearby events outside of that time range.

func (*SuggestedAnomalyBasedNRQLQuery) ImplementsSuggestedNRQLQuery

func (x *SuggestedAnomalyBasedNRQLQuery) ImplementsSuggestedNRQLQuery()

type SuggestedHistoryBasedNRQLQuery

type SuggestedHistoryBasedNRQLQuery struct {
	// The NRQL string to run for the suggested query
	NRQL string `json:"nrql"`
	// A human-readable title describing what the query shows
	Title string `json:"title"`
}

SuggestedHistoryBasedNRQLQuery - A query suggestion based on historical query patterns.

func (*SuggestedHistoryBasedNRQLQuery) ImplementsSuggestedNRQLQuery

func (x *SuggestedHistoryBasedNRQLQuery) ImplementsSuggestedNRQLQuery()

type SuggestedNRQLQuery

type SuggestedNRQLQuery struct {
	// The NRQL string to run for the suggested query
	NRQL string `json:"nrql"`
	// A human-readable title describing what the query shows
	Title string `json:"title"`
}

SuggestedNRQLQuery - Interface type representing a query suggestion.

func (*SuggestedNRQLQuery) ImplementsSuggestedNRQLQuery

func (x *SuggestedNRQLQuery) ImplementsSuggestedNRQLQuery()

type SuggestedNRQLQueryAnomaly

type SuggestedNRQLQueryAnomaly struct {
	// The approximate time window of the anomalous region
	TimeWindow TimeWindow `json:"timeWindow"`
}

SuggestedNRQLQueryAnomaly - Information about the anomaly upon which this analysis was based.

type SuggestedNRQLQueryInterface

type SuggestedNRQLQueryInterface interface {
	ImplementsSuggestedNRQLQuery()
}

SuggestedNRQLQuery - Interface type representing a query suggestion.

func UnmarshalSuggestedNRQLQueryInterface

func UnmarshalSuggestedNRQLQueryInterface(b []byte) (*SuggestedNRQLQueryInterface, error)

UnmarshalSuggestedNRQLQueryInterface unmarshals the interface into the correct type based on __typename provided by GraphQL

type SuggestedNRQLQueryResponse

type SuggestedNRQLQueryResponse struct {
	// List of suggested queries.
	Suggestions []SuggestedNRQLQueryInterface `json:"suggestions"`
}

SuggestedNRQLQueryResponse - A result type encapsulating suggested queries

func (*SuggestedNRQLQueryResponse) UnmarshalJSON

func (x *SuggestedNRQLQueryResponse) UnmarshalJSON(b []byte) error

special

type TimeWindow

type TimeWindow struct {
	// The end time of the time window the number of milliseconds since the Unix epoch.
	EndTime nrtime.EpochMilliseconds `json:"endTime,omitempty"`
	// The start time of the time window the number of milliseconds since the Unix epoch.
	StartTime nrtime.EpochMilliseconds `json:"startTime,omitempty"`
}

TimeWindow - Represents a time window.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL