The New Relic Query Language (NRQL) allows you to parse, transform, and analyse your data. NRQL is a very powerful query language, however queries can become complex and difficult to update in bulk. That is why we are excited to introduce NRQL Macros, a way to save a NRQL expression as a reusable, named shortcut.
Macros create a single source of truth for a snippet of NRQL, as well as shrink the amount of text in your query so it is easily understood by others.
In the new “NRQL Macros” section under “Administration” (or via our API), you can create and edit macros. Once named and created, macros can be used in a NRQL query by adding a “$” then the name of the macro. Below are three key examples how macros can be utilized:
1) Simplify a large query
Queries can become very large and complex. Using Macros you can group a large section of that query (Eg. a WHERE clause or WITH clause) all into one macro.
Pre-macro: SELECT count(*) FROM Transaction WHERE appId = 1234 AND appName!=’test’ AND http.statusCode IN (400, 401, 404)
Post-macro: SELECT count(*) FROM Transaction WHERE $where_macro
2) Create an alias for attributes with multiple namings
Not all data comes into New Relic name exactly the same thing, however they are indeed the same attribute. Using macros you can alias all of these namings.
Pre-macro: SELECT (podName OR pod_name OR pod.name) FROM Log
Post-macro: SELECT $podnameAlias FROM Log
3) Update an entire dashboard with one edit
Say you have a comprehensive dashboard with 30 widgets showing different angles of PageView data, however there is an addition you need to make to every widget (Eg. There is a test user that needs to be excluded from the data so it doesn’t skew it). Now you can update every widget by changing a single macro.
Pre-macro of widgets similar to this query: SELECT count(*) FROM PageView WHERE enduser.id != ‘test-user’
Post-macro of widgets similar to this query: SELECT count(*) FROM PageView WHERE $test_user_exclude
Having a macro in each widget gives you the ability to make changes to every widget with one change. No longer do you have to click into each widget one by one.
These three examples help give you a sense of what is possible, and hopefully spark some ideas on how you can simplify and/or optimize your NRQL queries.
To learn more about all the ins and outs of macros, check out our documentation.
이 블로그에 표현된 견해는 저자의 견해이며 반드시 New Relic의 견해를 반영하는 것은 아닙니다. 저자가 제공하는 모든 솔루션은 환경에 따라 다르며 New Relic에서 제공하는 상용 솔루션이나 지원의 일부가 아닙니다. 이 블로그 게시물과 관련된 질문 및 지원이 필요한 경우 Explorers Hub(support.newrelic.com)에서만 참여하십시오. 이 블로그에는 타사 사이트의 콘텐츠에 대한 링크가 포함될 수 있습니다. 이러한 링크를 제공함으로써 New Relic은 해당 사이트에서 사용할 수 있는 정보, 보기 또는 제품을 채택, 보증, 승인 또는 보증하지 않습니다.