Skip to content

Commit

Permalink
[Release] 2022-08-16 (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossifrancesco authored Aug 18, 2022
1 parent cc32c3b commit e5d196a
Show file tree
Hide file tree
Showing 10 changed files with 4,833 additions and 57 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ dist/
dist-image/
out/
sysdig/

# Local data
grafana-data-*/

# IDE settings
.idea/
58 changes: 38 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ This README discusses the installation and configuration instructions for the Sy
<img alt="Sysdig datasource" src="https://user-images.githubusercontent.com/5033993/39788129-bd3963fe-52dd-11e8-86b0-10e127660e68.gif" width="1200" />
</p>

---

## Support and Known Limitations

The Sysdig datasource plugin is currently in BETA and tested with Grafana version up to [8.5.5](https://github.com/grafana/grafana/releases/tag/v8.5.5).

**NOTE: this plugin is not supported with later versions of Grafana. Instead, use the official Prometheus data source plugin to query the Sysdig API. For more info: [Sysdig Docs](https://docs.sysdig.com/en/docs/sysdig-monitor/integrations-for-sysdig-monitor/collect-prometheus-metrics/configure-sysdig-with-grafana/).**

Known limitations of the Sysdig datasource plugin are listed below:
* [Annotations](http://docs.grafana.org/reference/annotations/) are leveraged to show Sysdig events, but not broadly supported.
* With Grafana you can enter any arbitrary [time range](https://grafana.com/docs/grafana/v8.5/dashboards/time-range-controls/), but data will be fetched according to retention and granularity restrictions as explained in [Sysdig Docs](https://docs.sysdig.com/en/docs/sysdig-monitor/explore/time-windows/#time-window-limitations).

---

## Getting Started

Expand All @@ -15,15 +28,26 @@ There are several installation approaches available for the Sysdig datasource pl

> **Note:** The Sysdig datasource plugin is currently not included in the [official & community built plugin page](https://grafana.com/plugins), and needs to be installed manually.
#### Compatibility

| Grafana Version | Plugin Version |
|-----------------|----------------|
| <= 7.3.10 | <= 0.10 |
| 7.4.0 - 8.5.5 | 0.11 |

> **Note:** Starting from version 8, Grafana will not load unsigned plugins.
> To load the sysdig plugin you must set the [allow_loading_unsigned_plugins](https://grafana.com/docs/grafana/v8.5/administration/configuration/#allow_loading_unsigned_plugins) property. (E.g. `allow_loading_unsigned_plugins=sysdig`)
> For more information about the configuration files, refer to the [Grafana docs](https://grafana.com/docs/grafana/v8.5/administration/configuration/#configuration-file-location).
#### Using a Grafana Docker Container

We offer a Docker container image based on Grafana that comes with the plugin pre-installed:

```
docker run -d -p 3000:3000 --name grafana sysdiglabs/grafana:latest
docker run -d -p 3000:3000 -e GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=sysdig --name grafana sysdiglabs/grafana:latest
```

> For more information, refer to the [Docker Hub repository page](https://hub.docker.com/r/sysdiglabs/grafana) for more information about the
> For more information, refer to the [Docker Hub repository page](https://hub.docker.com/r/sysdiglabs/grafana).
---

Expand All @@ -33,13 +57,13 @@ Alternatively, the default Grafana container image can be used as is, and the pl
```
mkdir grafana-data
mkdir grafana-data/plugins
curl https://download.sysdig.com/stable/grafana-sysdig-datasource/grafana-sysdig-datasource-v0.7.tgz -o sysdig.tgz
curl https://download.sysdig.com/stable/grafana-sysdig-datasource/grafana-sysdig-datasource-v0.11.tgz -o sysdig.tgz
tar zxf sysdig.tgz -C grafana-data/plugins
```
2. Start the container with the current user, to give read/write permissions to the data directory:
```
ID=$(id -u)
docker run -d --user $ID --volume "$PWD/grafana-data:/var/lib/grafana" -p 3000:3000 grafana/grafana:latest
docker run -d --user $ID --volume "$PWD/grafana-data:/var/lib/grafana" -p 3000:3000 -e GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=sysdig grafana/grafana:latest
```

> For more information, refer to the [Grafana installation documentation](http://docs.grafana.org/installation/docker/#grafana-container-using-bind-mounts) and the [Docker documentation](https://docs.docker.com/storage/bind-mounts/).
Expand All @@ -59,7 +83,7 @@ The plugin can be installed on any host where Grafana is installed. To install t
1. Open a shell terminal.
2. Run the series of commands below:
```
curl https://download.sysdig.com/stable/grafana-sysdig-datasource/grafana-sysdig-datasource-v0.7.tgz -o sysdig.tgz
curl https://download.sysdig.com/stable/grafana-sysdig-datasource/grafana-sysdig-datasource-v0.11.tgz -o sysdig.tgz
tar zxf sysdig.tgz
sudo cp -R sysdig /var/lib/grafana/plugins
sudo service grafana-server restart
Expand All @@ -74,7 +98,7 @@ sudo service grafana-server restart
1. Open a shell terminal.
2. Run the series of commands below:
```
curl https://download.sysdig.com/stable/grafana-sysdig-datasource/grafana-sysdig-datasource-v0.7.tgz -o sysdig.tgz
curl https://download.sysdig.com/stable/grafana-sysdig-datasource/grafana-sysdig-datasource-v0.11.tgz -o sysdig.tgz
tar zxf sysdig.tgz
cp -R sysdig /usr/local/var/lib/grafana/plugins
brew services restart grafana
Expand All @@ -85,7 +109,7 @@ brew services restart grafana

##### Windows

1. Download the plugin from: https://download.sysdig.com/stable/grafana-sysdig-datasource/grafana-sysdig-datasource-v0.7.zip
1. Download the plugin from: https://download.sysdig.com/stable/grafana-sysdig-datasource/grafana-sysdig-datasource-v0.11.zip
2. Install the plugin in the Grafana plugins folder.
3. Restart Grafana.

Expand Down Expand Up @@ -122,6 +146,12 @@ In Sysdig, number panels, bar charts and histograms display aggregated data (i.e

> **Note:** To maintain the same aggregation mechanism and precision offered by the Sysdig API, create panels with the "Fetch single data point" flag turned on. This will instruct the datasource to make an aggregated data request to the API.
### Table panels

Starting from Grafana 7.4, and Sysdig plugin 0.11, the table panel must be created with the "Fetch as table" flag turned on.
This flag can be used also with other Grafana panel types that requires data in a table format, like `Bar chart` and `Bar gauge`.

> **Note**: no migration is required for the existing panels.
### Filters

Expand Down Expand Up @@ -262,18 +292,6 @@ The complete example below contains dynamic rows and panels:

---


## Current limitations

The Sysdig datasource is currently in Beta. Sysdig will continue to release iterations to make the datasource more complete and robust; however, some issues may be encountered. A list of known limitations is provided below:

* The datasource is being tested with latest version of Grafana. If you're using older versions of Grafana and you find any issues, please report the issue and we'll make sure to support your version of Grafana!
* We leverage [annotations](http://docs.grafana.org/reference/annotations/) to show Sysdig events, but we don't support it just yet.
* With Grafana you can enter any arbitrary [time range](http://docs.grafana.org/reference/timerange/), but data will be fetched according to retention and granularity restrictions as explained in this [Sysdig Support page](https://support.sysdig.com/hc/en-us/articles/204889655).


## Support / Community

The Sysdig Datasource Plugin for Grafana is currently in beta. We'd love to hear from you and help you with it!

Join our [Public Slack](https://slack.sysdig.com) channel ([#grafana](https://sysdig.slack.com/messages/CA7RSQXK9)) for announcements and discussions.
We'd love to hear from you! Join our [Public Slack](https://slack.sysdig.com) channel ([#grafana](https://sysdig.slack.com/messages/CA7RSQXK9)) for announcements and discussions.
3 changes: 2 additions & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
0.10
0.11

2 changes: 1 addition & 1 deletion VERSION_GRAFANA
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0
8.5.5
50 changes: 50 additions & 0 deletions build/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

setup_env() {
echo "Prepare environment..."

GRAFANA_VERSION=`cat VERSION_GRAFANA`

DIST_PATH="dist"

PLUGIN_DIR="grafana-data-${GRAFANA_VERSION}/plugins"

USER_ID=$(id -u)

# Disabling interactive progress bar, and spinners gains 2x performances
# as stated on https://twitter.com/gavinjoyce/status/691773956144119808
npm config set progress false
npm config set spin false
}

start() {
echo "Cleaning up..."

rm -rf ${PLUGIN_DIR}
docker stop grafana-dev > /dev/null || true
docker rm grafana-dev > /dev/null || true

echo "Building..."

npm run build

mkdir -p ${PLUGIN_DIR}/sysdig

cp -R ${DIST_PATH}/. ${PLUGIN_DIR}/sysdig
rm -rf ${PLUGIN_DIR}/sysdig/test

echo "Build complete."

echo "Starting Grafana ${GRAFANA_VERSION} docker container with Sysdig plugin..."

mkdir -p grafana-data-${GRAFANA_VERSION}

docker run -p 3000:3000 --user $USER_ID -v "${PWD}/grafana-data-${GRAFANA_VERSION}:/var/lib/grafana" \
-e GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=sysdig \
--rm grafana/grafana:${GRAFANA_VERSION}

}

set -ex
setup_env
start
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"build": "./node_modules/grunt-cli/bin/grunt",
"test": "./node_modules/grunt-cli/bin/grunt mochaTest",
"clean": "rm -rf dist"
"clean": "rm -rf dist",
"start": "./build/start.sh"
},
"repository": {
"type": "git",
Expand Down
11 changes: 6 additions & 5 deletions src/data_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,19 @@ function getBatchId(userTime) {
}

function getRequests(options, requestTime) {
return options.targets.map((target) => getRequest(target, requestTime));
const isTabularFormat = options.targets[0].isTabularFormat;
return options.targets.map((target) => getRequest(target, requestTime, isTabularFormat));
}

function getRequest(target, requestTime) {
function getRequest(target, requestTime, isTabularFormat) {
if (requestTime) {
return {
format: {
type: 'data'
},
time: getTime(),
metrics: getMetrics(),
sort: getSort(),
sort: getSort(isTabularFormat),
paging: getPaging(),
scope: target.filter,
group: {
Expand Down Expand Up @@ -281,12 +282,12 @@ function getRequest(target, requestTime) {
}
}

function getSort() {
function getSort(isTabularFormat) {
const sortDirection = target.sortDirection || 'desc';

let sort;

if (target.isTabularFormat === false) {
if (isTabularFormat === false) {
sort = [{ v0: sortDirection }, { k0: sortDirection }];

if (target.segmentBy.length > 0) {
Expand Down
19 changes: 12 additions & 7 deletions src/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>

<!-- Segmentation -->
<div class="gf-form gf-form-inline" ng-repeat="item in ctrl.segmentByItems">
<div class="gf-form gf-form-inline" ng-repeat="item in ctrl.segmentByItems" ng-if="!ctrl.isTabularFormat() || ctrl.isFirstTarget()">
<div class="gf-form gf-form--grow">
<label class="gf-form-label width-12" ng-if="item.isFirst === true">
Segment by
Expand All @@ -68,17 +68,17 @@

<div style="min-width: 80px;">
<button class="btn btn-inverse" ng-click="ctrl.removeSegmentBy(item)">
<i class="fa fa-trash" />
<i class="fa fa-trash" ></i>
</button>
<button class="btn btn-inverse" ng-click="ctrl.addSegmentBy(item)">
<i class="fa fa-plus" />
<i class="fa fa-plus" ></i>
</button>
</div>
</div>
</div>

<!-- Filter -->
<div class="gf-form-inline" ng-if="ctrl.panel.type !== 'table' || ctrl.isFirstTarget()">
<div class="gf-form-inline" ng-if="!ctrl.isTabularFormat() || ctrl.isFirstTarget()">
<div class="gf-form gf-form--grow">
<label class="gf-form-label width-12">
Filter
Expand Down Expand Up @@ -107,13 +107,18 @@
<div class="gf-form gf-form--grow"></div>
<div class="gf-form">
<gf-form-switch class="gf-form" label="Fetch single data point" label-class="width-12" checked="ctrl.target.isSingleDataPoint"
on-change="ctrl.refresh()">
ng-disabled="ctrl.isTabularFormat()"
on-change="ctrl.refresh()"/>
</div>
<div class="gf-form">
<gf-form-switch class="gf-form" label="Fetch as table" label-class="width-12" checked="ctrl.target.isTabularFormat"
on-change="ctrl.onChangeTabularFormat()"/>
</div>
</div>
</div>

<!-- Alias -->
<div class="gf-form-inline" ng-if="ctrl.panel.type !== 'table' || ctrl.isFirstTarget()">
<div class="gf-form-inline" ng-if="!ctrl.isTabularFormat() || ctrl.isFirstTarget()">
<div class="gf-form gf-form--grow">
<label class="gf-form-label width-12">
Alias
Expand All @@ -127,4 +132,4 @@
<!-- Time series vs data point -->
<div class="gf-form gf-form-inline" ng-if="ctrl.target.isTabularFormat === false && ctrl.isFirstTarget()">
</div>
</query-editor-row>
</query-editor-row>
47 changes: 25 additions & 22 deletions src/query_ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ export class SysdigDatasourceQueryCtrl extends QueryCtrl {
}

this.target.sortDirection = this.target.sortDirection || 'desc';

// enforce tabular format to be applied when the panel type is a table
this.target.isTabularFormat = this.panel.type === 'table';
this.target.isSingleDataPoint = this.target.isTabularFormat;

this.segmentByItems = this.calculateSegmentByItems();
}
Expand All @@ -76,6 +74,10 @@ export class SysdigDatasourceQueryCtrl extends QueryCtrl {
return this.panel.targets.indexOf(this.target) === 0;
}

isTabularFormat() {
return this.panel.targets[0].isTabularFormat;
}

getLimitPlaceholder() {
return `${DEFAULT_PAGE_LIMIT} (element count)`;
}
Expand All @@ -90,11 +92,11 @@ export class SysdigDatasourceQueryCtrl extends QueryCtrl {
getMetricOptions(query) {
let parseMetric;
let options = {
areLabelsIncluded: this.panel.type === 'table',
areLabelsIncluded: this.isTabularFormat(),
match: query
};

if (this.panel.type !== 'table') {
if (!this.isTabularFormat()) {
parseMetric = (m) => ({ text: m.id, value: m.id });
} else {
parseMetric = (m) => {
Expand Down Expand Up @@ -211,30 +213,31 @@ export class SysdigDatasourceQueryCtrl extends QueryCtrl {
}

calculateSegmentByItems() {
if (this.panel.type !== 'table' || this.isFirstTarget()) {
if (this.target.segmentBy.length === 0) {
return [
{
isFirst: true,
canAdd: false,
segmentBy: null
}
];
} else {
return this.target.segmentBy.map((segmentBy, i) => ({
isFirst: i === 0,
canAdd: i === this.target.segmentBy.length - 1,
segmentBy
}));
}
if (this.target.segmentBy.length === 0) {
return [
{
isFirst: true,
canAdd: false,
segmentBy: null
}
];
} else {
return [];
return this.target.segmentBy.map((segmentBy, i) => ({
isFirst: i === 0,
canAdd: i === this.target.segmentBy.length - 1,
segmentBy
}));
}
}

toggleEditorMode() {
// noop
}

onChangeTabularFormat() {
this.target.isSingleDataPoint = this.target.isTabularFormat;
this.refresh();
}
}

SysdigDatasourceQueryCtrl.templateUrl = 'partials/query.editor.html';
Expand Down
Loading

0 comments on commit e5d196a

Please sign in to comment.