Skip to content

Commit fc1dd10

Browse files
fixes to grafana source manger
1 parent 95fec52 commit fc1dd10

File tree

4 files changed

+63
-46
lines changed

4 files changed

+63
-46
lines changed

integrations/source_manangers/grafana_source_manager.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,33 @@
1-
import json
21
import logging
32
import re
43
import string
5-
import requests
6-
from typing import TYPE_CHECKING, Optional, Union
4+
from typing import Optional, Union
75

86
from google.protobuf.struct_pb2 import Struct
9-
from google.protobuf.wrappers_pb2 import BoolValue, DoubleValue, StringValue
7+
from google.protobuf.wrappers_pb2 import DoubleValue, StringValue
108

11-
from alert_ops_engine.utils.string_utils import is_partial_match
12-
from connectors.utils import generate_credentials_dict
139
from integrations.source_api_processors.grafana_api_processor import GrafanaApiProcessor
14-
from integrations.source_asset_managers.asset_manager_facade import asset_manager_facade
15-
from playbooks_engine.executor.playbook_source_manager import PlaybookSourceManager
16-
from protos.event.assets.asset_pb2 import AccountConnectorAssets, AccountConnectorAssetsModelFilters
17-
from protos.event.base_pb2 import TimeRange
18-
from protos.event.connectors_pb2 import Connector as ConnectorProto
19-
from protos.event.connectors_pb2 import ConnectorKey as SourceKeyType
20-
from protos.event.connectors_pb2 import ConnectorMetadataModelType as SourceModelType
21-
from protos.event.connectors_pb2 import ConnectorType as Source
22-
from protos.event.literal_pb2 import Literal, LiteralType
23-
from protos.event.playbooks.playbook_commons_pb2 import (
10+
from integrations.source_manager import SourceManager
11+
from protos.base_pb2 import Source, SourceModelType, TimeRange
12+
from protos.connectors.connector_pb2 import Connector as ConnectorProto
13+
from protos.literal_pb2 import Literal, LiteralType
14+
from protos.playbooks.playbook_commons_pb2 import (
2415
ApiResponseResult,
2516
LabelValuePair,
2617
PlaybookTaskResult,
2718
PlaybookTaskResultType,
2819
TextResult,
2920
TimeseriesResult,
3021
)
31-
from protos.event.playbooks.source_task_definitions.grafana_task_pb2 import Grafana
32-
from protos.event.ui_definition_pb2 import FormField, FormFieldType
22+
from protos.playbooks.source_task_definitions.grafana_task_pb2 import Grafana
23+
from protos.ui_definition_pb2 import FormField, FormFieldType
24+
from utils.credentilal_utils import generate_credentials_dict
3325
from utils.proto_utils import dict_to_proto, proto_to_dict
34-
from utils.constants import *
35-
from connectors.utils import get_connector_key_type_string
36-
37-
if TYPE_CHECKING:
38-
from protos.event.assets.grafana_asset_pb2 import GrafanaAssetModel, GrafanaDashboardAssetModel, \
39-
GrafanaDatasourceAssetModel
4026

4127
logger = logging.getLogger(__name__)
4228

4329

44-
class GrafanaSourceManager(PlaybookSourceManager):
30+
class GrafanaSourceManager(SourceManager):
4531
# Constants for dynamic interval calculation
4632
MAX_DATA_POINTS = 70
4733
MIN_STEP_SIZE_SECONDS = 60 # Minimum interval is 1 minute

protos/playbooks/source_task_definitions/grafana_task.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
syntax = "proto3";
2-
package protos.event.playbooks;
2+
package protos.playbooks;
33

44
import "google/protobuf/wrappers.proto";
5-
import "protos/event/playbooks/source_task_definitions/promql_task.proto";
5+
import "protos/playbooks/source_task_definitions/promql_task.proto";
66

77

88
message Grafana {

protos/playbooks/source_task_definitions/grafana_task_pb2.py

Lines changed: 16 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/playbooks/source_task_definitions/grafana_task_pb2.pyi

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ class Grafana(google.protobuf.message.Message):
3535
PROMETHEUS_DATASOURCE_METRIC_EXECUTION: Grafana._TaskType.ValueType # 2
3636
QUERY_DASHBOARD_PANEL_METRIC: Grafana._TaskType.ValueType # 3
3737
EXECUTE_ALL_DASHBOARD_PANELS: Grafana._TaskType.ValueType # 4
38+
FETCH_DASHBOARD_VARIABLE_LABEL_VALUES: Grafana._TaskType.ValueType # 5
3839

3940
class TaskType(_TaskType, metaclass=_TaskTypeEnumTypeWrapper): ...
4041
UNKNOWN: Grafana.TaskType.ValueType # 0
4142
PROMQL_METRIC_EXECUTION: Grafana.TaskType.ValueType # 1
4243
PROMETHEUS_DATASOURCE_METRIC_EXECUTION: Grafana.TaskType.ValueType # 2
4344
QUERY_DASHBOARD_PANEL_METRIC: Grafana.TaskType.ValueType # 3
4445
EXECUTE_ALL_DASHBOARD_PANELS: Grafana.TaskType.ValueType # 4
46+
FETCH_DASHBOARD_VARIABLE_LABEL_VALUES: Grafana.TaskType.ValueType # 5
4547

4648
@typing_extensions.final
4749
class PromQlMetricExecution(google.protobuf.message.Message):
@@ -162,27 +164,51 @@ class Grafana(google.protobuf.message.Message):
162164
DASHBOARD_UID_FIELD_NUMBER: builtins.int
163165
PANEL_IDS_FIELD_NUMBER: builtins.int
164166
INTERVAL_FIELD_NUMBER: builtins.int
167+
TEMPLATE_VARIABLES_FIELD_NUMBER: builtins.int
165168
@property
166169
def dashboard_uid(self) -> google.protobuf.wrappers_pb2.StringValue: ...
167170
@property
168171
def panel_ids(self) -> google.protobuf.wrappers_pb2.StringValue: ...
169172
@property
170173
def interval(self) -> google.protobuf.wrappers_pb2.UInt64Value: ...
174+
@property
175+
def template_variables(self) -> google.protobuf.wrappers_pb2.StringValue: ...
171176
def __init__(
172177
self,
173178
*,
174179
dashboard_uid: google.protobuf.wrappers_pb2.StringValue | None = ...,
175180
panel_ids: google.protobuf.wrappers_pb2.StringValue | None = ...,
176181
interval: google.protobuf.wrappers_pb2.UInt64Value | None = ...,
182+
template_variables: google.protobuf.wrappers_pb2.StringValue | None = ...,
177183
) -> None: ...
178-
def HasField(self, field_name: typing_extensions.Literal["dashboard_uid", b"dashboard_uid", "interval", b"interval", "panel_ids", b"panel_ids"]) -> builtins.bool: ...
179-
def ClearField(self, field_name: typing_extensions.Literal["dashboard_uid", b"dashboard_uid", "interval", b"interval", "panel_ids", b"panel_ids"]) -> None: ...
184+
def HasField(self, field_name: typing_extensions.Literal["dashboard_uid", b"dashboard_uid", "interval", b"interval", "panel_ids", b"panel_ids", "template_variables", b"template_variables"]) -> builtins.bool: ...
185+
def ClearField(self, field_name: typing_extensions.Literal["dashboard_uid", b"dashboard_uid", "interval", b"interval", "panel_ids", b"panel_ids", "template_variables", b"template_variables"]) -> None: ...
186+
187+
@typing_extensions.final
188+
class FetchDashboardVariableLabelValuesTask(google.protobuf.message.Message):
189+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
190+
191+
DATASOURCE_UID_FIELD_NUMBER: builtins.int
192+
LABEL_NAME_FIELD_NUMBER: builtins.int
193+
@property
194+
def datasource_uid(self) -> google.protobuf.wrappers_pb2.StringValue: ...
195+
@property
196+
def label_name(self) -> google.protobuf.wrappers_pb2.StringValue: ...
197+
def __init__(
198+
self,
199+
*,
200+
datasource_uid: google.protobuf.wrappers_pb2.StringValue | None = ...,
201+
label_name: google.protobuf.wrappers_pb2.StringValue | None = ...,
202+
) -> None: ...
203+
def HasField(self, field_name: typing_extensions.Literal["datasource_uid", b"datasource_uid", "label_name", b"label_name"]) -> builtins.bool: ...
204+
def ClearField(self, field_name: typing_extensions.Literal["datasource_uid", b"datasource_uid", "label_name", b"label_name"]) -> None: ...
180205

181206
TYPE_FIELD_NUMBER: builtins.int
182207
PROMQL_METRIC_EXECUTION_FIELD_NUMBER: builtins.int
183208
PROMETHEUS_DATASOURCE_METRIC_EXECUTION_FIELD_NUMBER: builtins.int
184209
QUERY_DASHBOARD_PANEL_METRIC_FIELD_NUMBER: builtins.int
185210
EXECUTE_ALL_DASHBOARD_PANELS_FIELD_NUMBER: builtins.int
211+
FETCH_DASHBOARD_VARIABLE_LABEL_VALUES_FIELD_NUMBER: builtins.int
186212
type: global___Grafana.TaskType.ValueType
187213
@property
188214
def promql_metric_execution(self) -> global___Grafana.PromQlMetricExecution: ...
@@ -192,6 +218,8 @@ class Grafana(google.protobuf.message.Message):
192218
def query_dashboard_panel_metric(self) -> global___Grafana.QueryDashboardPanelMetricTask: ...
193219
@property
194220
def execute_all_dashboard_panels(self) -> global___Grafana.ExecuteAllDashboardPanelsTask: ...
221+
@property
222+
def fetch_dashboard_variable_label_values(self) -> global___Grafana.FetchDashboardVariableLabelValuesTask: ...
195223
def __init__(
196224
self,
197225
*,
@@ -200,9 +228,10 @@ class Grafana(google.protobuf.message.Message):
200228
prometheus_datasource_metric_execution: protos.playbooks.source_task_definitions.promql_task_pb2.PromQl.PromQlMetricExecution | None = ...,
201229
query_dashboard_panel_metric: global___Grafana.QueryDashboardPanelMetricTask | None = ...,
202230
execute_all_dashboard_panels: global___Grafana.ExecuteAllDashboardPanelsTask | None = ...,
231+
fetch_dashboard_variable_label_values: global___Grafana.FetchDashboardVariableLabelValuesTask | None = ...,
203232
) -> None: ...
204-
def HasField(self, field_name: typing_extensions.Literal["execute_all_dashboard_panels", b"execute_all_dashboard_panels", "prometheus_datasource_metric_execution", b"prometheus_datasource_metric_execution", "promql_metric_execution", b"promql_metric_execution", "query_dashboard_panel_metric", b"query_dashboard_panel_metric", "task", b"task"]) -> builtins.bool: ...
205-
def ClearField(self, field_name: typing_extensions.Literal["execute_all_dashboard_panels", b"execute_all_dashboard_panels", "prometheus_datasource_metric_execution", b"prometheus_datasource_metric_execution", "promql_metric_execution", b"promql_metric_execution", "query_dashboard_panel_metric", b"query_dashboard_panel_metric", "task", b"task", "type", b"type"]) -> None: ...
206-
def WhichOneof(self, oneof_group: typing_extensions.Literal["task", b"task"]) -> typing_extensions.Literal["promql_metric_execution", "prometheus_datasource_metric_execution", "query_dashboard_panel_metric", "execute_all_dashboard_panels"] | None: ...
233+
def HasField(self, field_name: typing_extensions.Literal["execute_all_dashboard_panels", b"execute_all_dashboard_panels", "fetch_dashboard_variable_label_values", b"fetch_dashboard_variable_label_values", "prometheus_datasource_metric_execution", b"prometheus_datasource_metric_execution", "promql_metric_execution", b"promql_metric_execution", "query_dashboard_panel_metric", b"query_dashboard_panel_metric", "task", b"task"]) -> builtins.bool: ...
234+
def ClearField(self, field_name: typing_extensions.Literal["execute_all_dashboard_panels", b"execute_all_dashboard_panels", "fetch_dashboard_variable_label_values", b"fetch_dashboard_variable_label_values", "prometheus_datasource_metric_execution", b"prometheus_datasource_metric_execution", "promql_metric_execution", b"promql_metric_execution", "query_dashboard_panel_metric", b"query_dashboard_panel_metric", "task", b"task", "type", b"type"]) -> None: ...
235+
def WhichOneof(self, oneof_group: typing_extensions.Literal["task", b"task"]) -> typing_extensions.Literal["promql_metric_execution", "prometheus_datasource_metric_execution", "query_dashboard_panel_metric", "execute_all_dashboard_panels", "fetch_dashboard_variable_label_values"] | None: ...
207236

208237
global___Grafana = Grafana

0 commit comments

Comments
 (0)