Skip to content

Commit

Permalink
Switching deprecated types and adding cors headers to dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
tolzhabayev committed Sep 25, 2024
1 parent 142144e commit b0e3ad0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/datasource-http-backend/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM node:18
FROM node:20

WORKDIR /usr/src/app

COPY . .

ENV NODE_ENV production
RUN npm install
RUN npm ci

EXPOSE 8080

Expand Down
9 changes: 8 additions & 1 deletion examples/datasource-http-backend/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ const express = require('express');
const app = express();
const port = 10000;


app.options('/metrics', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
res.send();
});
app.get('/metrics', (req, res) => {
const pointsN = 1024;
const dataPoints = [];
const multiplier = parseInt(req.query.multiplier) || 1;
const multiplier = parseInt(req.query.multiplier, 10) || 1;

for (let i = 0; i < pointsN; i++) {
const ts = new Date(Date.now() - i * 1000);
Expand All @@ -16,6 +22,7 @@ app.get('/metrics', (req, res) => {
}

res.setHeader('Content-Type', 'application/json');
res.setHeader('Access-Control-Allow-Origin', '*');
res.send(JSON.stringify({ dataPoints }));
});

Expand Down
3 changes: 2 additions & 1 deletion examples/datasource-http-backend/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DataQuery, DataSourceJsonData } from '@grafana/data';
import { DataSourceJsonData } from '@grafana/data';
import { DataQuery } from '@grafana/schema';

export interface MyQuery extends DataQuery {
multiplier: number;
Expand Down
6 changes: 3 additions & 3 deletions examples/datasource-http/src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DataSourceApi,
DataSourceInstanceSettings,
FieldType,
createDataFrame,
} from '@grafana/data';
import { getBackendSrv, isFetchError } from '@grafana/runtime';
import { DataSourceResponse, defaultQuery, MyDataSourceOptions, MyQuery } from './types';
Expand Down Expand Up @@ -35,14 +36,13 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {

// Return a constant for each query.
const data = options.targets.map((target) => {
const df: DataFrame = {
length: 2,
const df: DataFrame = createDataFrame({
refId: target.refId,
fields: [
{ name: 'Time', values: [from, to], type: FieldType.time, config: {} },
{ name: 'Value', values: [target.constant, target.constant], type: FieldType.number, config: {} },
],
};
});
return df;
});

Expand Down
3 changes: 2 additions & 1 deletion examples/datasource-http/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DataQuery, DataSourceJsonData } from '@grafana/data';
import { DataSourceJsonData } from '@grafana/data';
import { DataQuery } from '@grafana/schema';

export interface MyQuery extends DataQuery {
queryText?: string;
Expand Down

0 comments on commit b0e3ad0

Please sign in to comment.