Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit ede90d5

Browse files
eh-ampyroscopebot
andauthored
fix: multiple fixes (#15)
* Return a `noop` flamegraph when the request fails (eg when passing a broken query) * Set correct minimum version in `plugin.json`, before it was 7.0.0 but we required certain new functionalities * Fix typeahead * Add back logo --------- Co-authored-by: Pyroscope Bot <[email protected]>
1 parent c276541 commit ede90d5

File tree

13 files changed

+141
-48
lines changed

13 files changed

+141
-48
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- uses: actions/checkout@v3
5050
- uses: ./.github/actions/setup-node
5151
- name: Pull dependencies
52-
run: yarn
52+
run: yarn --frozen-lockfile
5353
- name: Build
5454
run: yarn build
5555
- name: Sign plugin
@@ -83,18 +83,6 @@ jobs:
8383
md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
8484
echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)"
8585
86-
87-
# A PR created by pyroscopebot (aka Release Please)
88-
# bumps package.json and CHANGELOG, which we then want to validate
89-
# If it's a user PR, don't check the version
90-
- uses: haya14busa/action-cond@v1
91-
id: ENABLE_VERSION_ANALYZER
92-
name: 'Enable linting version?'
93-
with:
94-
cond: ${{ github.event.pull_request.user.login }} == 'pyroscopebot'
95-
if_true: true
96-
if_false: false
97-
9886
- name: Lint plugin
9987
run: |
10088
export PATH="$(go env GOPATH)/bin/:$PATH"
@@ -103,7 +91,8 @@ jobs:
10391
pushd ./plugin-validator/pkg/cmd/plugincheck2
10492
go install
10593
popd
106-
plugincheck2 -config lint.config.yaml -sourceCodeUri=file://./ ${{ steps.metadata.outputs.archive }}
107-
env:
108-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10994
95+
plugincheck2 -strict -config lint.config.yaml -sourceCodeUri=file://./ ${{ steps.metadata.outputs.archive }}
96+
env:
97+
ENABLE_VERSION_ANALYZER: false
98+
DEBUG: 1

.github/workflows/release.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
${{ runner.os }}-${{ matrix.node-version }}-nodemodules-
4242
4343
- name: Pull dependencies
44-
run: yarn
44+
run: yarn --frozen-lockfile
4545
- name: Build
4646
run: yarn build
4747
- name: Sign plugin
@@ -82,18 +82,6 @@ jobs:
8282
zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r
8383
md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
8484
echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)"
85-
86-
# A PR created by pyroscopebot (aka Release Please)
87-
# bumps package.json and CHANGELOG, which we then want to validate
88-
# If it's a user PR, don't check the version
89-
- uses: haya14busa/action-cond@v1
90-
id: ENABLE_VERSION_ANALYZER
91-
name: 'Enable linting version?'
92-
with:
93-
cond: ${{ github.event.pull_request.user.login }} == 'pyroscopebot'
94-
if_true: true
95-
if_false: false
96-
9785
- name: Lint plugin
9886
run: |
9987
export PATH="$(go env GOPATH)/bin/:$PATH"
@@ -102,7 +90,11 @@ jobs:
10290
pushd ./plugin-validator/pkg/cmd/plugincheck2
10391
go install
10492
popd
105-
plugincheck2 -config lint.config.yaml -sourceCodeUri=file://./ ${{ steps.metadata.outputs.archive }}
93+
94+
plugincheck2 -strict -config lint.config.yaml -sourceCodeUri=file://./ ${{ steps.metadata.outputs.archive }}
95+
env:
96+
ENABLE_VERSION_ANALYZER: true
97+
DEBUG: 1
10698

10799
# until here it's pretty much the same as ci.yml
108100
# TODO: share the code somehow

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Changelog
22

3+
## [1.2.0](https://github.com/pyroscope-io/grafana-datasource-plugin/compare/v1.1.3...v1.2.0) (2023-03-09)
4+
5+
6+
### Features
7+
8+
* support template variables ([#9](https://github.com/pyroscope-io/grafana-datasource-plugin/issues/9)) ([cbe396c](https://github.com/pyroscope-io/grafana-datasource-plugin/commit/cbe396c46eb830e016f055b545cc62e292cc3b7b))
9+
310
## [1.1.3](https://github.com/pyroscope-io/pyroscope/compare/@pyroscope/[email protected]...@pyroscope/[email protected]) (2022-07-11)
411
Add a CHANGELOG.md
512

613

714
## 1.1.2 (2022-02-24)
815
Add support for [authenticated requests](https://github.com/pyroscope-io/pyroscope/pull/844).
9-

CONTRIBUTING.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,21 @@
33
## Releasing new versions
44
1. Merge the PR created by `Release Please`
55
2. Open [https://grafana.com/orgs/pyroscope/plugin-submissions/pyroscope-datasource](https://grafana.com/orgs/pyroscope/plugin-submissions/pyroscope-datasource) and submit the plugin, copying the links from this repository's releases.
6+
7+
## Fixing releases
8+
After submitting to Grafana, they may find issues.
9+
10+
If you fix these issues and publish a release, there will be a gap in grafana.
11+
For example:
12+
* Version 1.0.0 is already released and published to grafana
13+
* You release a new version 1.1.0
14+
* Grafana plugin process finds an error
15+
* You publish release version 1.1.1
16+
* Grafana plugin process approves that version
17+
* Now there's a gap (`1.0.0` -> `1.1.1`), since `1.1.0` was skipped
18+
19+
For that to not happen, you need to delete the previous release (1.1.0), so that it can be re-released.
20+
To do that:
21+
* Delete the release (via the ui)
22+
* Delete the tag associated with that release (via the ui)
23+
* Delete the commit Release Please uses (`git rebase -i MAIN ~2`, then pick `drop`). It requires force pushing to main, so enable that option for YOUR user only in the repo's settings.

cypress/fixtures/appNames.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[{"name":"pyroscope.server.cpu","spyName":"gospy","sampleRate":100,"units":"samples"},{"name":"pyroscope.server.goroutines","spyName":"gospy","units":"goroutines"},{"name":"pyroscope.server.block_count","spyName":"gospy","units":"lock_samples"},{"name":"pyroscope.server.block_duration","spyName":"gospy","units":"lock_nanoseconds"},{"name":"pyroscope.server.alloc_objects","spyName":"gospy","units":"objects"},{"name":"pyroscope.server.alloc_space","spyName":"gospy","units":"bytes"},{"name":"pyroscope.server.inuse_objects","spyName":"gospy","units":"objects"},{"name":"pyroscope.server.inuse_space","spyName":"gospy","units":"bytes"},{"name":"pyroscope.server.mutex_count","spyName":"gospy","units":"lock_samples"},{"name":"pyroscope.server.mutex_duration","spyName":"gospy","units":"lock_nanoseconds"}]
2+

cypress/integration/smoke.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,20 @@ describe('smoke', () => {
1414

1515
cy.wait('@renderRequest');
1616
});
17+
18+
it('auto completes', () => {
19+
cy.visit(
20+
'http://localhost:3000/d/single-panel/single-panel-dashboard?orgId=1&editPanel=2&from=1678718500926&to=1678719100926'
21+
);
22+
23+
cy.intercept('**/api/datasources/proxy/1/render/api/apps', {
24+
fixture: 'appNames',
25+
}).as('appNames');
26+
27+
// CTRL + SPACE
28+
cy.get('.query-editor-row [data-slate-editor]').clear().type(`{ctrl}`).trigger('keydown', { keyCode: 32 });
29+
30+
// 10 elements + header
31+
cy.get('ul.typeahead li').should('have.length', 11);
32+
});
1733
});

lint.config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
global:
22
enabled: true
3-
severity: error
43
jsonOutput: false
4+
reportAll: true
55

66
analyzers:
77
version:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pyroscope-datasource-plugin",
3-
"version": "1.1.3",
3+
"version": "1.2.0",
44
"description": "Flamegraph data provider",
55
"scripts": {
66
"cy:open": "cypress open",

src/QueryEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const QueryEditor = (props: Props) => {
1414
const loadAppNames = () => {
1515
return props.datasource.loadAppNames().then(
1616
(result) => {
17-
return result.data.map((value: string) => ({ label: value, value }));
17+
return result.map((value: string) => ({ label: value, value }));
1818
},
1919
(response) => {
2020
throw new Error(response.statusText);

src/datasource.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { getBackendSrv, BackendSrv, getTemplateSrv } from '@grafana/runtime';
1111

1212
import { defaultQuery, FlamegraphQuery, MyDataSourceOptions } from './types';
1313
import { deltaDiff } from './flamebearer';
14+
import { noopFlamegraph } from './noopFlamegraph';
1415

1516
export class DataSource extends DataSourceApi<FlamegraphQuery, MyDataSourceOptions> {
1617
constructor(instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>) {
@@ -31,15 +32,22 @@ export class DataSource extends DataSourceApi<FlamegraphQuery, MyDataSourceOptio
3132
// and also get rid of 'name', since it would affect the results
3233
const { name, ...newQuery } = { ...query, query: query.name };
3334

34-
const result = await this.backendSrv
35-
.fetch({
36-
method: 'GET',
37-
url: `${this.url}/render/render`,
38-
params: newQuery,
39-
})
40-
.toPromise();
41-
42-
return result;
35+
try {
36+
const result = await this.backendSrv
37+
.fetch({
38+
method: 'GET',
39+
url: `${this.url}/render/render`,
40+
params: newQuery,
41+
})
42+
.toPromise();
43+
44+
return result;
45+
} catch (e) {
46+
// Return a noop flamegraph, so that the panel doesn't crash
47+
return {
48+
data: noopFlamegraph,
49+
};
50+
}
4351
}
4452

4553
async metricFindQuery(query: string, options?: any) {
@@ -105,13 +113,25 @@ export class DataSource extends DataSourceApi<FlamegraphQuery, MyDataSourceOptio
105113
return result.data.map((x) => ({ text: x }));
106114
}
107115

116+
// fetchNames fetches all the application names
117+
// it returns nothing when it fails to communicate with the server
108118
fetchNames() {
109119
return this.backendSrv
110-
.fetch<string[]>({
120+
.fetch<Array<{ name: string }>>({
111121
method: 'GET',
112122
url: `${this.url}/render/api/apps`,
113123
})
114-
.toPromise();
124+
.toPromise()
125+
.then((response) => {
126+
if (!response) {
127+
return [];
128+
}
129+
130+
return response.data.map((a) => a.name);
131+
})
132+
.catch(() => {
133+
return [];
134+
});
115135
}
116136

117137
async query(options: DataQueryRequest<FlamegraphQuery>): Promise<DataQueryResponse> {
@@ -157,8 +177,14 @@ export class DataSource extends DataSourceApi<FlamegraphQuery, MyDataSourceOptio
157177
}
158178

159179
async testDatasource() {
160-
const names = await this.fetchNames();
161-
if (names && names.status === 200) {
180+
const response = await this.backendSrv
181+
.fetch<Array<{ name: string }>>({
182+
method: 'GET',
183+
url: `${this.url}/render/api/apps`,
184+
})
185+
.toPromise();
186+
187+
if (response && response.status === 200) {
162188
return {
163189
status: 'success',
164190
message: 'Success',

0 commit comments

Comments
 (0)