Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queries with both FACET and TIMESERIES fails on JSON unmarshalling #1078

Open
dsabsay opened this issue Jan 18, 2024 · 0 comments
Open

Queries with both FACET and TIMESERIES fails on JSON unmarshalling #1078

dsabsay opened this issue Jan 18, 2024 · 0 comments

Comments

@dsabsay
Copy link

dsabsay commented Jan 18, 2024

Description

When running a NRQL query that uses both FACET and TIMESERIES, the library returns an error because it cannot encode the results into the structs.

Go Version

go version go1.21.3 darwin/amd64

Current behavior

The following error is returned:

json: cannot unmarshal array into Go struct field NRDBResultContainer.data.Actor.Account.NRQL.otherResult of type nrdb.NRDBResult

Expected behavior

The results are returned without error (as they are in the New Relic UI).

Steps To Reproduce

package main

import (
	"fmt"
	"os"
	"time"

	"github.com/newrelic/newrelic-client-go/v2/newrelic"
	"github.com/newrelic/newrelic-client-go/v2/pkg/nrdb"
)

func threshold(client *newrelic.NewRelic) {
	accountID := 1234567

        // This query fails:
	// query := "SELECT percentile(duration, 95) AS 'foobar' FROM Transaction FACET request.method TIMESERIES 1 hours SINCE '2024-01-17 14:51:00 +0000' UNTIL '2024-01-17 19:51:00 +0000'"

        // These queries work:
	// query := "SELECT percentile(duration, 95) AS 'foobar' FROM Transaction FACET request.method SINCE '2024-01-17 14:51:00 +0000' UNTIL '2024-01-17 19:51:00 +0000'"
	query := "SELECT percentile(duration, 95) AS 'foobar' FROM Transaction TIMESERIES 1 hours SINCE '2024-01-17 14:51:00 +0000' UNTIL '2024-01-17 19:51:00 +0000'"

	resultContainer, err := client.Nrdb.Query(accountID, nrdb.NRQL(query))
	if err != nil {
		fmt.Printf("error: %v\n", err)
	}

	fmt.Printf("resultContainer: %#v\n", resultContainer)
}

func main() {
	key := os.Getenv("NR_API_KEY")
	client, err := newrelic.New(
		newrelic.ConfigPersonalAPIKey(key),
		newrelic.ConfigHTTPTimeout(time.Second*30),
	)
	if err != nil {
		fmt.Println(err)
		return
	}

	threshold(client)
}

Set NR_API_KEY env var. Then use comments to try each of the 3 queries. The first one (with FACET and TIMESERIES) does not work.

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

No branches or pull requests

1 participant