Skip to content

Commit

Permalink
Format code (#140)
Browse files Browse the repository at this point in the history
* Format code

Signed-off-by: Bartosz Zurkowski <zurkowski.bartosz@gmail.com>

* Format code

Signed-off-by: Bartosz Zurkowski <zurkowski.bartosz@gmail.com>

* Adjust flake config to black

Signed-off-by: Bartosz Zurkowski <zurkowski.bartosz@gmail.com>

Signed-off-by: Bartosz Zurkowski <zurkowski.bartosz@gmail.com>
  • Loading branch information
bzurkowski authored Sep 11, 2022
1 parent 7350550 commit 3b3ddcb
Show file tree
Hide file tree
Showing 71 changed files with 984 additions and 965 deletions.
2 changes: 0 additions & 2 deletions helm/examples/integrations/elastalert/enhancements.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


class MongoDBHostFailedInReplicaSet(BaseEnhancement):

def process(self, match):
data = match["log_processed"]
host = data["attr"]["host"]
Expand All @@ -30,7 +29,6 @@ def process(self, match):


class MongoDBHeartbeatFailed(BaseEnhancement):

def process(self, match):
data = match["log_processed"]
host = data["attr"]["target"]
Expand Down
14 changes: 8 additions & 6 deletions orca/api/apis/v1/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,26 @@


class Alerts(Resource):

def __init__(self, api, graph):
super().__init__()
self._graph = graph

def get(self):
query_schema = AlertQuerySchema()
query = query_schema.load(request.args)
timepoint = query['time_point']
include_deleted = query['deleted']
timepoint = query["time_point"]
include_deleted = query["deleted"]
alert_data = self._graph.get_nodes(
time_point=timepoint, properties={'kind': 'alert'}, include_deleted=include_deleted)
time_point=timepoint,
properties={"kind": "alert"},
include_deleted=include_deleted,
)
alert_schema = AlertSchema(many=True)
result = alert_schema.dump(alert_data)
return result, 200


def initialize(graph):
api = Namespace('alerts', description='Alerts API')
api.add_resource(Alerts, '/', resource_class_args=[graph])
api = Namespace("alerts", description="Alerts API")
api.add_resource(Alerts, "/", resource_class_args=[graph])
return api
20 changes: 11 additions & 9 deletions orca/api/apis/v1/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,29 @@


class Graph(Resource):

def __init__(self, api, graph):
super().__init__()
self._graph = graph

def get(self):
query_schema = GraphQuerySchema()
query = query_schema.load(request.args)
timepoint = query['time_point']
include_deleted = query['deleted']
timepoint = query["time_point"]
include_deleted = query["deleted"]
graph_data = {
'nodes': self._graph.get_nodes(time_point=timepoint, include_deleted=include_deleted),
'links': self._graph.get_links(time_point=timepoint, include_deleted=include_deleted)
"nodes": self._graph.get_nodes(
time_point=timepoint, include_deleted=include_deleted
),
"links": self._graph.get_links(
time_point=timepoint, include_deleted=include_deleted
),
}
graph_schema = GraphSchema()
result = graph_schema.dump(graph_data)
return result, 200


class GraphNode(Resource):

def __init__(self, api, graph):
super().__init__()
self._graph = graph
Expand All @@ -52,7 +54,7 @@ def get(self, node_id):


def initialize(graph):
api = Namespace('graph', description='Graph API')
api.add_resource(Graph, '/', resource_class_args=[graph])
api.add_resource(GraphNode, '/nodes/<node_id>', resource_class_args=[graph])
api = Namespace("graph", description="Graph API")
api.add_resource(Graph, "/", resource_class_args=[graph])
api.add_resource(GraphNode, "/nodes/<node_id>", resource_class_args=[graph])
return api
5 changes: 3 additions & 2 deletions orca/api/apis/v1/ingestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ def register(self, ingestor_bundle):
endpoint = "/%s" % ingestor_bundle.name.lower()

self._api.add_resource(
IngestorResource, endpoint, resource_class_args=(ingestor,))
IngestorResource, endpoint, resource_class_args=(ingestor,)
)


def initialize(graph):
api = Namespace('ingestor', description='Ingestor API')
api = Namespace("ingestor", description="Ingestor API")

event_dispatcher = linker.EventDispatcher()
graph.add_listener(event_dispatcher)
Expand Down
4 changes: 2 additions & 2 deletions orca/api/apiv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


def initialize(graph):
blueprint = Blueprint('api', __name__, url_prefix='/v1')
api = Api(blueprint, title='OpenRCA API')
blueprint = Blueprint("api", __name__, url_prefix="/v1")
api = Api(blueprint, title="OpenRCA API")
api.add_namespace(graph_ns.initialize(graph))
api.add_namespace(ingestor_ns.initialize(graph))
api.add_namespace(alerts_ns.initialize(graph))
Expand Down
6 changes: 2 additions & 4 deletions orca/api/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@


class Manager(cotyledon.ServiceManager):

def initialize(self):
graph_lock = multiprocessing.Lock()
self.add(APIService, workers=1, args=(graph_lock,))


class APIService(cotyledon.Service):

def __init__(self, worker_id, graph_lock):
super().__init__(worker_id)
self._graph_lock = graph_lock
Expand All @@ -47,10 +45,10 @@ def run(self):
self._set_logging()
app = self._init_app()
CORS(app)
app.run(host='0.0.0.0')
app.run(host="0.0.0.0")

def _set_logging(self):
log = logging.getLogger('werkzeug')
log = logging.getLogger("werkzeug")
log.setLevel(logging.ERROR)

def _init_app(self):
Expand Down
12 changes: 6 additions & 6 deletions orca/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class DetailedNodeSchema(NodeSchema):

class LinkSchema(GraphObjectSchema):

source = fields.String(attribute='source.id')
target = fields.String(attribute='target.id')
source = fields.String(attribute="source.id")
target = fields.String(attribute="target.id")


class GraphSchema(Schema):
Expand All @@ -47,10 +47,10 @@ class AlertSchema(Schema):
id = fields.String()
origin = fields.String()
kind = fields.String()
name = fields.String(attribute='properties.name')
message = fields.String(attribute='properties.message')
severity = fields.String(attribute='properties.severity')
source = fields.Nested(NodeSchema(), attribute='properties.source_mapping')
name = fields.String(attribute="properties.name")
message = fields.String(attribute="properties.message")
severity = fields.String(attribute="properties.severity")
source = fields.Nested(NodeSchema(), attribute="properties.source_mapping")
properties = fields.Raw()
created_at = fields.String()
updated_at = fields.String()
Expand Down
19 changes: 9 additions & 10 deletions orca/common/clients/istio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,32 @@


class ResourceProxyFactory(object):

@staticmethod
def get(kind):
client = k8s.ClientFactory.get()
if kind == 'virtual_service':
if kind == "virtual_service":
return k8s.CustomResourceProxy(
kind='virtual_service',
kind="virtual_service",
list_fn=client.CustomObjectsApi().list_cluster_custom_object,
group="networking.istio.io",
version="v1alpha3",
plural="virtualservices"
plural="virtualservices",
)
elif kind == 'destination_rule':
elif kind == "destination_rule":
return k8s.CustomResourceProxy(
kind='destination_rule',
kind="destination_rule",
list_fn=client.CustomObjectsApi().list_cluster_custom_object,
group="networking.istio.io",
version="v1alpha3",
plural="destinationrules"
plural="destinationrules",
)
elif kind == 'gateway':
elif kind == "gateway":
return k8s.CustomResourceProxy(
kind='gateway',
kind="gateway",
list_fn=client.CustomObjectsApi().list_cluster_custom_object,
group="networking.istio.io",
version="v1alpha3",
plural="gateways"
plural="gateways",
)
else:
raise Exception("Unknown kind %s" % kind)
Loading

0 comments on commit 3b3ddcb

Please sign in to comment.