Skip to content

Commit

Permalink
Only use pprof on specific build tags
Browse files Browse the repository at this point in the history
  * Problem: It is not permitted to access environment variables from plugins. PPROF_ENDPOINT is not an accessible variable.

    Details: Code rule violation found in /tmp/validator3055756003/pkg/main.go at line 27
  • Loading branch information
diericd committed May 27, 2024
1 parent 6ccdf1b commit ef44c40
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 168 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
major = 2
minor = 0
patch = 0
prerelease = -alpha
prerelease =
project_name=factry-historian-datasource

COMMIT=$(shell git rev-parse --short HEAD)
Expand Down
17 changes: 0 additions & 17 deletions pkg/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"net/http"
"os"
"time"

historianDataSource "github.com/factrylabs/factry-historian-datasource.git/pkg/datasource"
"github.com/grafana/grafana-plugin-sdk-go/backend"
Expand All @@ -12,22 +10,7 @@ import (
_ "net/http/pprof" // #nosec G108 -- pprof is only enabled if env var PPROF_ENDPOINT is set
)

func startPprof(endpoint string) {
go func() {
server := &http.Server{
Addr: endpoint,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
_ = server.ListenAndServe()
}()
}

func main() {
if os.Getenv("PPROF_ENDPOINT") != "" {
startPprof(os.Getenv("PPROF_ENDPOINT"))
}

backend.SetupPluginEnvironment(historianDataSource.PluginID)
err := datasource.Serve(historianDataSource.NewDataSource())
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/pprof.go
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
//go:build pprof
// +build pprof

package main

func init() {
go func (){
server := &http.Server{
Addr: ":1234",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
_ = server.ListenAndServe()
}
}
26 changes: 7 additions & 19 deletions provisioning/dashboards/examples/batch_events.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "datasource",
"id": "factry-historian-datasource",
"name": "Factry Historian Datasource",
"version": "2.0.0-alpha"
"version": "2.0.0"
},
{
"type": "grafana",
Expand Down Expand Up @@ -101,9 +101,7 @@
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"reducer": ["sum"],
"show": false
},
"showHeader": true
Expand All @@ -116,12 +114,8 @@
"uid": "${DS_FACTRY_HISTORIAN}"
},
"query": {
"Assets": [
"/MyFactory.*ProductionLine.*/"
],
"EventTypes": [
"8ee49756-2db9-11ed-b42c-0242ac170006"
],
"Assets": ["/MyFactory.*ProductionLine.*/"],
"EventTypes": ["8ee49756-2db9-11ed-b42c-0242ac170006"],
"Properties": [],
"PropertyFilter": [],
"QueryAssetProperties": false,
Expand Down Expand Up @@ -243,15 +237,9 @@
"uid": "${DS_FACTRY_HISTORIAN}"
},
"query": {
"Assets": [
"/MyFactory.*ProductionLine.*/"
],
"EventTypes": [
"8ee49756-2db9-11ed-b42c-0242ac170006"
],
"Properties": [
"Temperature"
],
"Assets": ["/MyFactory.*ProductionLine.*/"],
"EventTypes": ["8ee49756-2db9-11ed-b42c-0242ac170006"],
"Properties": ["Temperature"],
"PropertyFilter": [],
"QueryAssetProperties": false,
"Statuses": [],
Expand Down
70 changes: 18 additions & 52 deletions provisioning/dashboards/examples/measurementandassets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "datasource",
"id": "factry-historian-datasource",
"name": "Factry Historian Datasource",
"version": "2.0.0-alpha"
"version": "2.0.0"
},
{
"type": "grafana",
Expand Down Expand Up @@ -143,12 +143,8 @@
"uid": "${DS_FACTRY_HISTORIAN}"
},
"query": {
"AssetProperties": [
"Temperature"
],
"Assets": [
"/.*/"
],
"AssetProperties": ["Temperature"],
"Assets": ["/.*/"],
"Options": {
"Aggregation": {
"Name": "mean",
Expand All @@ -157,9 +153,7 @@
"DisplayDatabaseName": false,
"DisplayDescription": false,
"FillInitialEmptyValues": false,
"GroupBy": [
"status"
],
"GroupBy": ["status"],
"IncludeLastKnownPoint": false,
"MetadataAsLabels": true,
"Tags": {
Expand Down Expand Up @@ -258,13 +252,9 @@
"uid": "${DS_FACTRY_HISTORIAN}"
},
"query": {
"Databases": [
"568a43d2-1169-11ec-9be3-59e8def62e23"
],
"Databases": ["568a43d2-1169-11ec-9be3-59e8def62e23"],
"IsRegex": false,
"Measurements": [
"75e9aad0-06f1-11ef-be27-0242ac130002"
],
"Measurements": ["75e9aad0-06f1-11ef-be27-0242ac130002"],
"Options": {
"Aggregation": {
"Name": "mean",
Expand All @@ -273,9 +263,7 @@
"DisplayDatabaseName": false,
"DisplayDescription": false,
"FillInitialEmptyValues": false,
"GroupBy": [
"status"
],
"GroupBy": ["status"],
"IncludeLastKnownPoint": false,
"MetadataAsLabels": true,
"Tags": {
Expand Down Expand Up @@ -379,13 +367,9 @@
"uid": "${DS_FACTRY_HISTORIAN}"
},
"query": {
"Databases": [
"568a43d2-1169-11ec-9be3-59e8def62e23"
],
"Databases": ["568a43d2-1169-11ec-9be3-59e8def62e23"],
"IsRegex": false,
"Measurements": [
"75e9aad0-06f1-11ef-be27-0242ac130002"
],
"Measurements": ["75e9aad0-06f1-11ef-be27-0242ac130002"],
"Options": {
"Aggregation": {
"Name": "mean",
Expand All @@ -394,9 +378,7 @@
"DisplayDatabaseName": false,
"DisplayDescription": false,
"FillInitialEmptyValues": false,
"GroupBy": [
"status"
],
"GroupBy": ["status"],
"IncludeLastKnownPoint": false,
"MetadataAsLabels": true,
"Tags": {
Expand Down Expand Up @@ -455,9 +437,7 @@
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
Expand All @@ -473,13 +453,9 @@
"uid": "${DS_FACTRY_HISTORIAN}"
},
"query": {
"Databases": [
"568a43d2-1169-11ec-9be3-59e8def62e23"
],
"Databases": ["568a43d2-1169-11ec-9be3-59e8def62e23"],
"IsRegex": false,
"Measurements": [
"d31ffe3c-0879-11ef-be27-0242ac130002"
],
"Measurements": ["d31ffe3c-0879-11ef-be27-0242ac130002"],
"Options": {
"Aggregation": {
"Name": "mean",
Expand All @@ -488,9 +464,7 @@
"DisplayDatabaseName": false,
"DisplayDescription": false,
"FillInitialEmptyValues": true,
"GroupBy": [
"status"
],
"GroupBy": ["status"],
"IncludeLastKnownPoint": true,
"MetadataAsLabels": true,
"Tags": {
Expand Down Expand Up @@ -594,12 +568,8 @@
"uid": "${DS_FACTRY_HISTORIAN}"
},
"query": {
"AssetProperties": [
"Temperature"
],
"Assets": [
"c0638bec-753b-11ed-87ee-0242ac170006"
],
"AssetProperties": ["Temperature"],
"Assets": ["c0638bec-753b-11ed-87ee-0242ac170006"],
"Options": {
"Aggregation": {
"Name": "mean",
Expand All @@ -608,9 +578,7 @@
"DisplayDatabaseName": false,
"DisplayDescription": false,
"FillInitialEmptyValues": false,
"GroupBy": [
"status"
],
"GroupBy": ["status"],
"IncludeLastKnownPoint": false,
"MetadataAsLabels": true,
"Tags": {
Expand Down Expand Up @@ -724,9 +692,7 @@
},
"DisplayDatabaseName": false,
"DisplayDescription": false,
"GroupBy": [
"status"
],
"GroupBy": ["status"],
"IncludeLastKnownPoint": false,
"MetadataAsLabels": true,
"Tags": {
Expand Down
Loading

0 comments on commit ef44c40

Please sign in to comment.