-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grafana): compelete grafana data sources
- Loading branch information
1 parent
aa387a4
commit fe5fbc6
Showing
9 changed files
with
237 additions
and
20 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: 1 | ||
datasources: | ||
- name: Tempo | ||
type: tempo | ||
access: proxy | ||
orgId: 1 | ||
url: http://tempo-query-frontend.tempo.svc.cluster.local:3100 | ||
basicAuth: false | ||
version: 1 | ||
editable: true | ||
apiVersion: 1 | ||
uid: tempo | ||
jsonData: | ||
httpMethod: GET | ||
serviceMap: | ||
datasourceUid: Mimir-OtelMetrics-Tenant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import List, Optional | ||
from pydantic import BaseModel, validator, ValidationError | ||
|
||
|
||
|
||
|
||
class PostgresInput(BaseModel): | ||
name:str = "Postgres" | ||
url:str = "localhost:5432" | ||
user:str = "grafana" | ||
editable: bool = True | ||
database:str = "grafana" | ||
sslmode:str = "disable" | ||
password:str = "Password!" | ||
maxOpenConns:int = 100 | ||
maxIdleConns:int = 100 | ||
maxIdleConnsAuto:bool = True | ||
connMaxLifetime:int = 14400 | ||
postgresVersion:int = 903 | ||
timescaledb:bool = False | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from typing import List, Optional | ||
from pydantic import BaseModel, validator, ValidationError | ||
|
||
|
||
class TraceID(BaseModel): | ||
datasourceUid:str = "my_jaeger_uid" | ||
name:str = "traceID" | ||
class PrometheusInput(BaseModel): | ||
name:str = "Prometheus" | ||
url:str = "http://localhost:9090" | ||
editable: bool = True | ||
httpMethod:str = "POST" | ||
manageAlerts:bool = True | ||
prometheusType:str = "Prometheus" | ||
prometheusVersion:str = "2.44.0" | ||
cacheLevel:str = 'High' | ||
disableRecordingRules:bool = False | ||
incrementalQueryOverlapWindow:str = "10m" | ||
trace_id: TraceID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import Optional, List | ||
from pydantic import BaseModel,PrivateAttr,Field | ||
|
||
class TracesToLogsV2(BaseModel): | ||
datasourceUid: str = 'loki' | ||
spanStartTimeShift: str = '-2m' | ||
spanEndTimeShift: str = '2m' | ||
filterByTraceID: bool = True | ||
filterBySpanID: bool = True | ||
|
||
class ServiceMap(BaseModel): | ||
datasourceUid: str = 'Mimir-OtelMetrics-Tenant' | ||
|
||
class NodeGraph(BaseModel): | ||
enabled: bool = True | ||
|
||
class JsonData(BaseModel): | ||
httpMethod: str = 'GET' | ||
tracesToLogsV2: Optional[TracesToLogsV2] = TracesToLogsV2() | ||
serviceMap: Optional[ServiceMap] = ServiceMap() | ||
nodeGraph: Optional[NodeGraph] = NodeGraph() | ||
|
||
class Datasource(BaseModel): | ||
name: str = 'Tempo' | ||
type: str = Field(default='tempo') | ||
access: str = Field(default="proxy") | ||
orgId: int = Field(default=1) | ||
url: str = 'http://tempo-query-frontend.tempo.svc.cluster.local:3100' | ||
basicAuth: bool = False | ||
version: int = Field(default=1) | ||
editable: bool = True | ||
apiVersion: int = Field(default=1) | ||
uid: str = Field(default="tempo") | ||
jsonData: JsonData = JsonData() | ||
|
||
class TempoInput(BaseModel): | ||
apiVersion: int = Field(default=1) | ||
datasources: List[Datasource] = [Datasource()] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import yaml | ||
import os | ||
|
||
def postgres_template(input): | ||
json_template = { | ||
"apiVersion": 1, | ||
"datasources": [ | ||
{ | ||
"name": input.name, | ||
"type": "postgres", | ||
"url": input.url, | ||
"user": input.user, | ||
"editable": input.editable, | ||
"secureJsonData": { | ||
"password": input.password | ||
}, | ||
"jsonData": { | ||
"database": input.database, | ||
"sslmode": input.sslmode, | ||
"maxOpenConns": input.maxOpenConns, | ||
"maxIdleConns": input.maxIdleConns, | ||
"maxIdleConnsAuto": input.maxIdleConnsAuto, | ||
"connMaxLifetime": input.connMaxLifetime, | ||
"postgresVersion": input.postgresVersion, | ||
"timescaledb": input.timescaledb | ||
} | ||
} | ||
] | ||
} | ||
|
||
|
||
dir = "app/media/MyGrafana" | ||
os.makedirs(dir) | ||
os.path.join(dir, 'postgresql.yml') | ||
|
||
file=open("app/media/MyGrafana/postgresql.yml","w") | ||
yaml.dump(json_template,file,default_flow_style=False,sort_keys=False) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import yaml | ||
import os | ||
|
||
def pormetheus_template(input): | ||
json_template = { | ||
"apiVersion": 1, | ||
"datasources": [ | ||
{ | ||
"name": input.name, | ||
"uid": "prometheus", | ||
"type": "prometheus", | ||
"access": "proxy", | ||
"url": input.url, | ||
"editable": input.editable, | ||
"jsonData": { | ||
"httpMethod": input.httpMethod, | ||
"manageAlerts": input.manageAlerts, | ||
"prometheusType": input.prometheusType, | ||
"prometheusVersion": input.prometheusVersion, | ||
"cacheLevel": input.cacheLevel, | ||
"disableRecordingRules": input.disableRecordingRules, | ||
"incrementalQueryOverlapWindow": input.incrementalQueryOverlapWindow, | ||
"exemplarTraceIdDestinations": [ | ||
{ | ||
"datasourceUid": input.trace_id.datasourceUid, | ||
"name": input.trace_id.name | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
|
||
|
||
dir = "app/media/MyGrafana" | ||
os.makedirs(dir) | ||
os.path.join(dir, 'prometheus.yml') | ||
|
||
file=open("app/media/MyGrafana/prometheus.yml","w") | ||
yaml.dump(json_template,file,default_flow_style=False,sort_keys=False) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import yaml | ||
import os | ||
|
||
def remove_none_values(d): | ||
if isinstance(d, dict): | ||
return {k: remove_none_values(v) for k, v in d.items() if v is not None} | ||
elif isinstance(d, list): | ||
return [remove_none_values(i) for i in d if i is not None] | ||
return d | ||
|
||
def tempo_template(input): | ||
dir = 'app/media/MyGrafana' | ||
compose_total = input.dict(exclude_none=True) | ||
|
||
|
||
os.makedirs(dir) | ||
os.path.join(dir, 'tempo.yaml') | ||
|
||
file=open("app/media/MyGrafana/tempo.yaml","w") | ||
yaml.dump(compose_total,file,default_flow_style=False, sort_keys=False) | ||
file.close() | ||
|
||
|