Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions integrations/source_manangers/grafana_source_manager.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
import json
import logging
import re
import string
import requests
from typing import TYPE_CHECKING, Optional, Union
from typing import Optional, Union

from google.protobuf.struct_pb2 import Struct
from google.protobuf.wrappers_pb2 import BoolValue, DoubleValue, StringValue
from google.protobuf.wrappers_pb2 import DoubleValue, StringValue

from alert_ops_engine.utils.string_utils import is_partial_match
from connectors.utils import generate_credentials_dict
from integrations.source_api_processors.grafana_api_processor import GrafanaApiProcessor
from integrations.source_asset_managers.asset_manager_facade import asset_manager_facade
from playbooks_engine.executor.playbook_source_manager import PlaybookSourceManager
from protos.event.assets.asset_pb2 import AccountConnectorAssets, AccountConnectorAssetsModelFilters
from protos.event.base_pb2 import TimeRange
from protos.event.connectors_pb2 import Connector as ConnectorProto
from protos.event.connectors_pb2 import ConnectorKey as SourceKeyType
from protos.event.connectors_pb2 import ConnectorMetadataModelType as SourceModelType
from protos.event.connectors_pb2 import ConnectorType as Source
from protos.event.literal_pb2 import Literal, LiteralType
from protos.event.playbooks.playbook_commons_pb2 import (
from integrations.source_manager import SourceManager
from protos.base_pb2 import Source, SourceModelType, TimeRange
from protos.connectors.connector_pb2 import Connector as ConnectorProto
from protos.literal_pb2 import Literal, LiteralType
from protos.playbooks.playbook_commons_pb2 import (
ApiResponseResult,
LabelValuePair,
PlaybookTaskResult,
PlaybookTaskResultType,
TextResult,
TimeseriesResult,
)
from protos.event.playbooks.source_task_definitions.grafana_task_pb2 import Grafana
from protos.event.ui_definition_pb2 import FormField, FormFieldType
from protos.playbooks.source_task_definitions.grafana_task_pb2 import Grafana
from protos.ui_definition_pb2 import FormField, FormFieldType
from utils.credentilal_utils import generate_credentials_dict
from utils.proto_utils import dict_to_proto, proto_to_dict
from utils.constants import *
from connectors.utils import get_connector_key_type_string

if TYPE_CHECKING:
from protos.event.assets.grafana_asset_pb2 import GrafanaAssetModel, GrafanaDashboardAssetModel, \
GrafanaDatasourceAssetModel

logger = logging.getLogger(__name__)


class GrafanaSourceManager(PlaybookSourceManager):
class GrafanaSourceManager(SourceManager):
# Constants for dynamic interval calculation
MAX_DATA_POINTS = 70
MIN_STEP_SIZE_SECONDS = 60 # Minimum interval is 1 minute
Expand Down
4 changes: 2 additions & 2 deletions protos/playbooks/source_task_definitions/grafana_task.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";
package protos.event.playbooks;
package protos.playbooks;

import "google/protobuf/wrappers.proto";
import "protos/event/playbooks/source_task_definitions/promql_task.proto";
import "protos/playbooks/source_task_definitions/promql_task.proto";


message Grafana {
Expand Down
30 changes: 16 additions & 14 deletions protos/playbooks/source_task_definitions/grafana_task_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 34 additions & 5 deletions protos/playbooks/source_task_definitions/grafana_task_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ class Grafana(google.protobuf.message.Message):
PROMETHEUS_DATASOURCE_METRIC_EXECUTION: Grafana._TaskType.ValueType # 2
QUERY_DASHBOARD_PANEL_METRIC: Grafana._TaskType.ValueType # 3
EXECUTE_ALL_DASHBOARD_PANELS: Grafana._TaskType.ValueType # 4
FETCH_DASHBOARD_VARIABLE_LABEL_VALUES: Grafana._TaskType.ValueType # 5

class TaskType(_TaskType, metaclass=_TaskTypeEnumTypeWrapper): ...
UNKNOWN: Grafana.TaskType.ValueType # 0
PROMQL_METRIC_EXECUTION: Grafana.TaskType.ValueType # 1
PROMETHEUS_DATASOURCE_METRIC_EXECUTION: Grafana.TaskType.ValueType # 2
QUERY_DASHBOARD_PANEL_METRIC: Grafana.TaskType.ValueType # 3
EXECUTE_ALL_DASHBOARD_PANELS: Grafana.TaskType.ValueType # 4
FETCH_DASHBOARD_VARIABLE_LABEL_VALUES: Grafana.TaskType.ValueType # 5

@typing_extensions.final
class PromQlMetricExecution(google.protobuf.message.Message):
Expand Down Expand Up @@ -162,27 +164,51 @@ class Grafana(google.protobuf.message.Message):
DASHBOARD_UID_FIELD_NUMBER: builtins.int
PANEL_IDS_FIELD_NUMBER: builtins.int
INTERVAL_FIELD_NUMBER: builtins.int
TEMPLATE_VARIABLES_FIELD_NUMBER: builtins.int
@property
def dashboard_uid(self) -> google.protobuf.wrappers_pb2.StringValue: ...
@property
def panel_ids(self) -> google.protobuf.wrappers_pb2.StringValue: ...
@property
def interval(self) -> google.protobuf.wrappers_pb2.UInt64Value: ...
@property
def template_variables(self) -> google.protobuf.wrappers_pb2.StringValue: ...
def __init__(
self,
*,
dashboard_uid: google.protobuf.wrappers_pb2.StringValue | None = ...,
panel_ids: google.protobuf.wrappers_pb2.StringValue | None = ...,
interval: google.protobuf.wrappers_pb2.UInt64Value | None = ...,
template_variables: google.protobuf.wrappers_pb2.StringValue | None = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["dashboard_uid", b"dashboard_uid", "interval", b"interval", "panel_ids", b"panel_ids"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["dashboard_uid", b"dashboard_uid", "interval", b"interval", "panel_ids", b"panel_ids"]) -> None: ...
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: ...
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: ...

@typing_extensions.final
class FetchDashboardVariableLabelValuesTask(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

DATASOURCE_UID_FIELD_NUMBER: builtins.int
LABEL_NAME_FIELD_NUMBER: builtins.int
@property
def datasource_uid(self) -> google.protobuf.wrappers_pb2.StringValue: ...
@property
def label_name(self) -> google.protobuf.wrappers_pb2.StringValue: ...
def __init__(
self,
*,
datasource_uid: google.protobuf.wrappers_pb2.StringValue | None = ...,
label_name: google.protobuf.wrappers_pb2.StringValue | None = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["datasource_uid", b"datasource_uid", "label_name", b"label_name"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["datasource_uid", b"datasource_uid", "label_name", b"label_name"]) -> None: ...

TYPE_FIELD_NUMBER: builtins.int
PROMQL_METRIC_EXECUTION_FIELD_NUMBER: builtins.int
PROMETHEUS_DATASOURCE_METRIC_EXECUTION_FIELD_NUMBER: builtins.int
QUERY_DASHBOARD_PANEL_METRIC_FIELD_NUMBER: builtins.int
EXECUTE_ALL_DASHBOARD_PANELS_FIELD_NUMBER: builtins.int
FETCH_DASHBOARD_VARIABLE_LABEL_VALUES_FIELD_NUMBER: builtins.int
type: global___Grafana.TaskType.ValueType
@property
def promql_metric_execution(self) -> global___Grafana.PromQlMetricExecution: ...
Expand All @@ -192,6 +218,8 @@ class Grafana(google.protobuf.message.Message):
def query_dashboard_panel_metric(self) -> global___Grafana.QueryDashboardPanelMetricTask: ...
@property
def execute_all_dashboard_panels(self) -> global___Grafana.ExecuteAllDashboardPanelsTask: ...
@property
def fetch_dashboard_variable_label_values(self) -> global___Grafana.FetchDashboardVariableLabelValuesTask: ...
def __init__(
self,
*,
Expand All @@ -200,9 +228,10 @@ class Grafana(google.protobuf.message.Message):
prometheus_datasource_metric_execution: protos.playbooks.source_task_definitions.promql_task_pb2.PromQl.PromQlMetricExecution | None = ...,
query_dashboard_panel_metric: global___Grafana.QueryDashboardPanelMetricTask | None = ...,
execute_all_dashboard_panels: global___Grafana.ExecuteAllDashboardPanelsTask | None = ...,
fetch_dashboard_variable_label_values: global___Grafana.FetchDashboardVariableLabelValuesTask | None = ...,
) -> None: ...
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: ...
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: ...
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: ...
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: ...
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: ...
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: ...

global___Grafana = Grafana