grafana/public/app/plugins/datasource/cloudwatch/__mocks__/dashboardOnLoadedEvent.ts
Erik Sundell 254577ba56
CloudWatch: Cross-account querying support (#59362)
* Lattice: Point to private prerelease of aws-sdk-go (#515)

* point to private prerelease of aws-sdk-go

* fix build issue

* Lattice: Adding a feature toggle (#549)

* Adding a feature toggle for lattice

* Change name of feature toggle

* Lattice: List accounts (#543)

* Separate layers

* Introduce testify/mock library

Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com>

* point to version that includes metric api changes (#574)

* add accounts component (#575)

* Test refactor: remove unneeded clientFactoryMock (#581)

* Lattice: Add monitoring badge (#576)

* add monitoring badge

* fix tests

* solve conflict

* Lattice: Add dynamic label for account display name (#579)

* Build: Automatically sync lattice-main with OSS

* Lattice: Point to private prerelease of aws-sdk-go (#515)

* point to private prerelease of aws-sdk-go

* fix build issue

* Lattice: Adding a feature toggle (#549)

* Adding a feature toggle for lattice

* Change name of feature toggle

* Lattice: List accounts (#543)

* Separate layers

* Introduce testify/mock library

Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com>

* point to version that includes metric api changes (#574)

* add accounts component (#575)

* Test refactor: remove unneeded clientFactoryMock (#581)

* Lattice: Add monitoring badge (#576)

* add monitoring badge

* fix tests

* solve conflict

* add account label

Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com>
Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com>

* fix import

* solve merge related problem

* add account info (#608)

* add back namespaces handler

* Lattice: Parse account id and return it to frontend (#609)

* parse account id and return to frontend

* fix route test

* only show badge when feature toggle is enabled (#615)

* Lattice: Refactor resource response type and return account (#613)

* refactor resource response type

* remove not used file.

* go lint

* fix tests

* remove commented code

* Lattice: Use account as input when listing metric names and dimensions (#611)

* use account in resource requests

* add account to response

* revert accountInfo to accountId

* PR feedback

* unit test account in list metrics response

* remove not used asserts

* don't assert on response that is not relevant to the test

* removed dupe test

* pr feedback

* rename request package (#626)

* Lattice: Move account component and add tooltip (#630)

* move accounts component to the top of metric stat editor

* add tooltip

* CloudWatch: add account to GetMetricData queries (#627)

* Add AccountId to metric stat query

* Lattice: Account variable support  (#625)

* add variable support in accounts component

* add account variable query type

* update variables

* interpolate variable before its sent to backend

* handle variable change in hooks

* remove not used import

* Update public/app/plugins/datasource/cloudwatch/components/Account.tsx

Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com>

* Update public/app/plugins/datasource/cloudwatch/hooks.ts

Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com>

* add one more unit test

Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com>

* cleanup (#629)

* Set account Id according to crossAccountQuerying feature flag in backend (#632)

* CloudWatch: Change spelling of feature-toggle (#634)

* Lattice Logs (#631)

* Lattice Logs

* Fixes after CR

* Lattice: Bug: fix dimension keys request (#644)

* fix dimension keys

* fix lint

* more lint

* CloudWatch: Add tests for QueryData with AccountId (#637)

* Update from breaking change (#645)

* Update from breaking change

* Remove extra interface and methods

Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com>

* CloudWatch: Add business logic layer for getting log groups (#642)



Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com>

* Lattice: Fix - unset account id in region change handler (#646)

* move reset of account to region change handler

* fix broken test

* Lattice: Add account id to metric stat query deep link (#656)

add account id to metric stat link

* CloudWatch: Add new log groups handler for cross-account querying (#643)

* Lattice: Add feature tracking (#660)

* add tracking for account id prescense in metrics query

* also check feature toggle

* fix broken test

* CloudWatch: Add route for DescribeLogGroups for cross-account querying (#647)

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>

* Lattice: Handle account id default value (#662)

* make sure right type is returned

* set right default values

* Suggestions to lattice changes (#663)

* Change ListMetricsWithPageLimit response to slice of non-pointers

* Change GetAccountsForCurrentUserOrRole response to be not pointer

* Clean test Cleanup calls in test

* Remove CloudWatchAPI as part of mock

* Resolve conflicts

* Add Latest SDK (#672)

* add tooltip (#674)

* Docs: Add documentation for CloudWatch cross account querying (#676)

* wip docs

* change wordings

* add sections about metrics and logs

* change from monitoring to observability

* Update docs/sources/datasources/aws-cloudwatch/_index.md

Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com>

* Update docs/sources/datasources/aws-cloudwatch/query-editor/index.md

Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com>

* Update docs/sources/datasources/aws-cloudwatch/query-editor/index.md

Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com>

* Update docs/sources/datasources/aws-cloudwatch/query-editor/index.md

Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com>

* Update docs/sources/datasources/aws-cloudwatch/query-editor/index.md

Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com>

* apply pr feedback

* fix file name

* more pr feedback

* pr feedback

Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com>
Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com>

* use latest version of the aws-sdk-go

* Fix tests' mock response type

* Remove change in Azure Monitor

Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com>
Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com>
Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com>
2022-11-28 12:39:12 +01:00

765 lines
18 KiB
TypeScript

import { DashboardLoadedEvent } from '@grafana/data';
import { CloudWatchQuery } from '../types';
export const CloudWatchDashboardLoadedEvent = new DashboardLoadedEvent({
dashboardId: 'dashboard123',
orgId: 1,
userId: 2,
grafanaVersion: 'v9.0.0',
queries: {
cloudwatch: [
{
accountId: '123456789',
datasource: {
type: 'cloudwatch',
uid: '123',
},
dimensions: {
InstanceId: 'i-123',
},
expression: '',
hide: false,
id: '',
label: '',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'us-east-1',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {},
expression: '',
id: '',
matchExact: true,
metricEditorMode: 1,
metricName: '',
metricQueryType: 1,
namespace: '',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'us-east-1',
sql: {
from: {
property: {
name: 'AWS/EC2',
type: 'string',
},
type: 'property',
},
groupBy: {
expressions: [
{
property: {
name: 'InstanceId',
type: 'string',
},
type: 'groupBy',
},
],
type: 'and',
},
limit: 5,
orderBy: {
name: 'AVG',
type: 'function',
},
orderByDirection: 'DESC',
select: {
name: 'AVG',
parameters: [
{
name: 'CPUUtilization',
type: 'functionParameter',
},
],
type: 'function',
},
},
sqlExpression: 'SELECT AVG(CPUUtilization) FROM "AWS/EC2" GROUP BY InstanceId ORDER BY AVG() DESC LIMIT 5',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {},
expression: '',
id: '',
matchExact: true,
metricEditorMode: 1,
metricName: '',
metricQueryType: 1,
namespace: '',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'us-east-1',
sql: {
from: {
property: {
name: '$namespace',
type: 'string',
},
type: 'property',
},
groupBy: {
expressions: [
{
property: {
name: '$dimensionkey',
type: 'string',
},
type: 'groupBy',
},
],
type: 'and',
},
limit: 5,
orderBy: {
name: 'SUM',
type: 'function',
},
orderByDirection: '$direction',
select: {
name: '$aggregation',
parameters: [
{
name: '$metric',
type: 'functionParameter',
},
],
type: 'function',
},
},
sqlExpression:
'SELECT $aggregation($metric) FROM "$namespace" GROUP BY $dimensionkey ORDER BY SUM() $direction LIMIT 5',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {},
expression: '',
id: '',
matchExact: true,
metricEditorMode: 1,
metricName: '',
metricQueryType: 1,
namespace: '',
period: '900',
queryMode: 'Metrics',
refId: 'A',
region: 'us-east-1',
sql: {
from: {
name: 'SCHEMA',
parameters: [
{
name: 'AWS/EC2',
type: 'functionParameter',
},
{
name: 'InstanceId',
type: 'functionParameter',
},
],
type: 'function',
},
orderByDirection: 'DESC',
select: {
name: 'AVG',
parameters: [
{
name: 'CPUUtilization',
type: 'functionParameter',
},
],
type: 'function',
},
},
sqlExpression: 'SELECT AVG(CPUUtilization) FROM SCHEMA("AWS/EC2", InstanceId)',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {},
expression: '',
hide: false,
id: '',
matchExact: true,
metricEditorMode: 0,
metricName: '',
metricQueryType: 1,
namespace: '',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'default',
sql: {
from: {
property: {
name: 'AWS/EC2',
type: 'string',
},
type: 'property',
},
groupBy: {
expressions: [
{
property: {
name: 'InstanceId',
type: 'string',
},
type: 'groupBy',
},
],
type: 'and',
},
limit: 5,
orderBy: {
name: 'MAX',
type: 'function',
},
orderByDirection: 'DESC',
select: {
name: 'AVG',
parameters: [
{
name: 'CPUUtilization',
type: 'functionParameter',
},
],
type: 'function',
},
},
sqlExpression: 'SELECT AVG(CPUUtilization) FROM "AWS/EC2" GROUP BY InstanceId ORDER BY MAX() DESC LIMIT 5',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {},
expression: '',
id: '',
matchExact: true,
metricEditorMode: 0,
metricName: '',
metricQueryType: 1,
namespace: '',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'us-east-1',
sql: {
from: {
property: {
name: 'AWS/EC2',
type: 'string',
},
type: 'property',
},
groupBy: {
expressions: [
{
property: {
name: 'InstanceId',
type: 'string',
},
type: 'groupBy',
},
],
type: 'and',
},
limit: 5,
orderBy: {
name: 'AVG',
type: 'function',
},
orderByDirection: 'DESC',
select: {
name: 'AVG',
parameters: [
{
name: 'CPUUtilization',
type: 'functionParameter',
},
],
type: 'function',
},
},
sqlExpression: 'SELECT AVG(CPUUtilization) FROM "AWS/EC2" GROUP BY InstanceId ORDER BY AVG() DESC LIMIT 5',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {},
expression: '',
id: '',
matchExact: true,
metricEditorMode: 0,
metricName: '',
metricQueryType: 1,
namespace: '',
period: '900',
queryMode: 'Metrics',
refId: 'A',
region: 'us-east-1',
sql: {
from: {
name: 'SCHEMA',
parameters: [
{
name: 'AWS/EC2',
type: 'functionParameter',
},
{
name: 'InstanceId',
type: 'functionParameter',
},
],
type: 'function',
},
orderByDirection: 'DESC',
select: {
name: 'AVG',
parameters: [
{
name: 'CPUUtilization',
type: 'functionParameter',
},
],
type: 'function',
},
},
sqlExpression: 'SELECT AVG(CPUUtilization) FROM SCHEMA("AWS/EC2", InstanceId)',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {},
expression: '',
id: '',
matchExact: true,
metricEditorMode: 1,
metricName: '',
metricQueryType: 1,
namespace: 'AWS/EC2',
period: '300',
queryMode: 'Metrics',
refId: 'A',
region: 'default',
sql: {
select: {
name: 'AVG',
type: 'function',
},
},
sqlExpression: 'SELECT AVG(CPUUtilization) FROM "AWS/EC2" GROUP BY InstanceId',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {},
expression: 'REMOVE_EMPTY(SEARCH(\'{"AWS/EC2","InstanceId"} MetricName="CPUUtilization"\', \'Average\', 900))',
id: '',
matchExact: true,
metricEditorMode: 1,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: 'i-123',
},
expression: 'REMOVE_EMPTY(SEARCH(\'{"AWS/EC2","InstanceId"} MetricName="CPUUtilization"\', \'Average\', 900))',
id: 'a',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: 'query a times 2',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: 'i-123',
},
expression: 'a * 2',
hide: false,
id: 'b',
matchExact: true,
metricEditorMode: 1,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'B',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
datasource: {
type: 'cloudwatch',
uid: 'P7DC3E4760CFAC4AP',
},
expression: 'fields @timestamp, @message | sort @timestamp desc | limit 300 ',
id: '',
logGroupNames: ['/aws/lambda/hello-world', '/aws/sagemaker/Endpoints/test', '/aws/sagemaker/test'],
namespace: '',
queryMode: 'Logs',
refId: 'A',
region: 'default',
statsGroups: [],
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'APZ8b_Fnz',
},
dimensions: {
InstanceId: '*',
},
expression: '',
id: '',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '{{InstanceId}}',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: '$dimensionValue',
},
expression: '',
expressionMode: 'math',
hide: false,
id: 'a',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryMode: 'sql',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'B',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: 'Network Out',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: 'i-123',
},
expression: '',
expressionMode: 'math',
hide: true,
id: '',
matchExact: true,
metricEditorMode: 0,
metricName: 'NetworkOut',
metricQueryMode: 'metricStat',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '{{InstanceId}}',
datasource: {
type: 'cloudwatch',
uid: 'YEc9mclMk',
},
dimensions: {
InstanceId: 'i-123',
},
expression: '',
id: '',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'us-east-2',
sqlExpression: '',
statistic: '$stats',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: 'i-123',
},
expression: '',
id: 'a',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: '*',
},
expression: 'a / 0',
hide: false,
id: '',
matchExact: true,
metricEditorMode: 1,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'B',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: '*',
},
expression: "REMOVE_EMPTY(SEARCH('', 'Average', 900))",
id: '',
matchExact: true,
metricEditorMode: 1,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'us-east-2',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: '*',
},
expression: '',
id: 'a',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: '*',
},
expression: '',
hide: false,
id: 'a',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'B',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: 'i-123',
},
expression: '',
id: 'a',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'A',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: '*',
},
expression: 'a / ',
hide: false,
id: '',
matchExact: true,
metricEditorMode: 1,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: 'Metrics',
refId: 'B',
region: 'default',
sqlExpression: '',
statistic: 'Average',
},
{
alias: '',
datasource: {
type: 'cloudwatch',
uid: 'abc',
},
dimensions: {
InstanceId: '*',
},
expression: 'a / ',
hide: false,
id: '',
matchExact: true,
metricEditorMode: 0,
metricName: 'CPUUtilization',
metricQueryType: 0,
namespace: 'AWS/EC2',
period: '',
queryMode: '',
refId: 'B',
region: 'default',
sqlExpression: '',
statistic: '',
},
] as CloudWatchQuery[],
},
});