Skip to content

Commit 98c7624

Browse files
authored
Merge pull request #116 from scalyr/DSET-3658-cross-team-support
DSET-3658 Cross-team query support
2 parents 0758c0f + c8cd388 commit 98c7624

File tree

9 files changed

+50
-11
lines changed

9 files changed

+50
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 3.1.2
4+
5+
- Cross-team query support.
6+
37
## 3.1.1
48

59
- Bugfix around use of query options (max data points & interval)

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ dashboard using Scalyr data.
116116

117117
![PowerQuery](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/master/src/img/PowerQuery.png)
118118

119+
7. **Cross Team Search** - The AccountEmails field is used to specify which
120+
teams the query should be run against. Works the same as
121+
[Cross Team Search](https://app.scalyr.com/help/graphs#crossTeam) in the
122+
DataSet app. More information on teams can be found
123+
[here](https://app.scalyr.com/help/teams). Note that the owner of the Log
124+
Read API key used to setup the DataSet Datasource must be a member of all
125+
teams being queried.
126+
127+
![CrossTeamQuery](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/master/src/img/CrossTeamQuery.png)
128+
119129
You’ve successfully installed, configured and created a graph in Grafana using
120130
Dataset data!
121131

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sentinelone-dataset-datasource",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"description": "Scalyr Observability Platform",
55
"scripts": {
66
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",

pkg/plugin/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewDataSetClient(dataSetUrl string, apiKey string) DataSetClient {
5757
}
5858

5959
func (d *dataSetClient) newRequest(method, url string, body io.Reader) (*http.Request, error) {
60-
const VERSION = "3.1.1"
60+
const VERSION = "3.1.2"
6161

6262
if err := d.rateLimiter.Wait(context.Background()); err != nil {
6363
log.DefaultLogger.Error("error applying rate limiter", "err", err)

pkg/plugin/plugin.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ func (d *DataSetDatasource) QueryData(ctx context.Context, req *backend.QueryDat
5757
}
5858

5959
type queryModel struct {
60-
Expression string `json:"expression"`
61-
QueryType string `json:"queryType"`
62-
Format string `json:"format"`
63-
BreakDownFacetValue *string `json:"breakDownFacetValue"`
64-
Label *string `json:"label"`
60+
Expression string `json:"expression"`
61+
QueryType string `json:"queryType"`
62+
Format string `json:"format"`
63+
BreakDownFacetValue *string `json:"breakDownFacetValue"`
64+
Label *string `json:"label"`
65+
AccountEmails []string `json:"accountEmails"`
6566
}
6667

6768
func (d *DataSetDatasource) query(ctx context.Context, query backend.DataQuery) backend.DataResponse {
@@ -117,6 +118,10 @@ func (d *DataSetDatasource) query(ctx context.Context, query backend.DataQuery)
117118
}
118119
}
119120

121+
if qm.AccountEmails != nil && len(qm.AccountEmails) > 0 {
122+
request.AccountEmails = qm.AccountEmails
123+
}
124+
120125
var result *LRQResult
121126
result, response.Error = d.dataSetClient.DoLRQRequest(ctx, request)
122127
if response.Error != nil {

src/QueryEditor.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defaults } from 'lodash';
2-
import React, { ChangeEvent, ReactElement } from 'react';
3-
import { ActionMeta, InlineField, InlineFieldRow, Input, Select, TextArea } from '@grafana/ui';
2+
import React, { ChangeEvent, ReactElement, useState } from 'react';
3+
import { ActionMeta, InlineField, InlineFieldRow, Input, Select, MultiSelect, TextArea } from '@grafana/ui';
44
import { QueryEditorProps, SelectableValue } from '@grafana/data';
55
import { DataSource } from './datasource';
66
import { defaultQuery, MyDataSourceOptions, MyQuery, queryTypes } from './types';
@@ -12,6 +12,8 @@ export function QueryEditor(props: Props): ReactElement {
1212
const { datasource } = props;
1313
const { loading, topFacets } = useFacetsQuery(datasource);
1414
const query = defaults(props.query, defaultQuery);
15+
const [ accountEmails, setAccountEmails ] = useState<Array<SelectableValue<string>>>(
16+
(query.accountEmails || []).map(v => ({label: v, value: v})));
1517

1618
const onExpressionChange = (event: ChangeEvent<HTMLInputElement>) => {
1719
const { onChange, query } = props;
@@ -37,6 +39,13 @@ export function QueryEditor(props: Props): ReactElement {
3739
onChange({ ...query, label: event.target.value });
3840
};
3941

42+
const onAccountEmailsChange = (values: Array<SelectableValue<string>>, actionMeta: ActionMeta) => {
43+
const { onChange, query, onRunQuery } = props;
44+
setAccountEmails(values);
45+
onChange({ ...query, accountEmails: values.length > 0 ? values.map((v) => {return v.value;}) : null });
46+
onRunQuery();
47+
};
48+
4049
const onBlur = async () => {
4150
const { onRunQuery } = props;
4251
onRunQuery();
@@ -65,7 +74,7 @@ export function QueryEditor(props: Props): ReactElement {
6574
</InlineField>
6675
</InlineFieldRow>
6776
<InlineFieldRow>
68-
{query.queryType === 'Standard' && topFacets.length > 0 && (
77+
{query.queryType === 'Standard' && (
6978
<InlineField label="Breakdown" grow>
7079
<Select
7180
options={topFacets}
@@ -85,6 +94,16 @@ export function QueryEditor(props: Props): ReactElement {
8594
<Input type="text" value={query.label || ''} onChange={onLabelChange} />
8695
</InlineField>
8796
</InlineFieldRow>
97+
<InlineFieldRow>
98+
<InlineField label="AccountEmails" grow>
99+
<MultiSelect
100+
value={accountEmails}
101+
allowCustomValue
102+
isClearable
103+
onChange={onAccountEmailsChange}
104+
/>
105+
</InlineField>
106+
</InlineFieldRow>
88107
</>
89108
);
90109
}

src/img/CrossTeamQuery.png

97.1 KB
Loading

src/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"path": "img/DatasetConfig.png"
4444
}
4545
],
46-
"version": "3.1.1",
46+
"version": "3.1.2",
4747
"updated": "2023-03-31"
4848
},
4949
"dependencies": {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface MyQuery extends DataQuery {
55
queryType: any;
66
breakDownFacetValue: string | undefined | null;
77
label: string | undefined | null;
8+
accountEmails: Array<string | undefined> | undefined | null;
89
}
910

1011
export const defaultQuery: Partial<MyQuery> = {

0 commit comments

Comments
 (0)