Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/Matvey-Kuk/labels-i…
Browse files Browse the repository at this point in the history
…n-metrics' into Matvey-Kuk/labels-in-metrics
  • Loading branch information
Matvey-Kuk committed Sep 22, 2024
2 parents 1e4f4d9 + 38ff5f2 commit 48e1868
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 32 deletions.
19 changes: 18 additions & 1 deletion keep-ui/app/incidents/[id]/incident-timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { useIncidentAlerts } from "utils/hooks/useIncidents";
import { IncidentDto } from "../models";
import Image from "next/image";
import AlertSeverity from "app/alerts/alert-severity";
import { EmptyStateCard } from "@/components/ui/EmptyStateCard";
import { useRouter } from "next/navigation";

const severityColors = {
critical: "bg-red-300",
Expand Down Expand Up @@ -237,6 +239,20 @@ const AlertBar: React.FC<AlertBarProps> = ({
);
};

const IncidentTimelineNoAlerts: React.FC = () => {
const router = useRouter();
return (
<div className="h-80">
<EmptyStateCard
title="Timeline not available"
description="No alerts found for this incident. Go to the alerts feed and assign alerts to view the timeline."
buttonText="Assign alerts to this incident"
onClick={() => router.push("/alerts/feed")}
/>
</div>
);
};

export default function IncidentTimeline({
incident,
}: {
Expand Down Expand Up @@ -313,7 +329,8 @@ export default function IncidentTimeline({
return {};
}, [auditEvents, alerts]);

if (auditEventsLoading || !auditEvents || alertsLoading) return <>No Data</>;
if (auditEventsLoading || !auditEvents || alertsLoading)
return <IncidentTimelineNoAlerts />;

const {
startTime,
Expand Down
12 changes: 11 additions & 1 deletion keep-ui/app/incidents/[id]/incident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useRouter } from "next/navigation";
import IncidentTimeline from "./incident-timeline";
import { CiBellOn, CiViewTimeline } from "react-icons/ci";
import { IoIosGitNetwork } from "react-icons/io";
import { EmptyStateCard } from "@/components/ui/EmptyStateCard";

interface Props {
incidentId: string;
Expand Down Expand Up @@ -72,7 +73,16 @@ export default function IncidentView({ incidentId }: Props) {
<TabPanel>
<IncidentTimeline incident={incident} />
</TabPanel>
<TabPanel>Coming Soon...</TabPanel>
<TabPanel>
<div className="h-80">
<EmptyStateCard
title="Coming Soon..."
description="Topology view of the incident is coming soon."
buttonText="Go to Topology"
onClick={() => router.push("/topology")}
/>
</div>
</TabPanel>
</TabPanels>
</TabGroup>
</div>
Expand Down
4 changes: 2 additions & 2 deletions keep-ui/app/workflows/builder/builder-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ const useStore = create<FlowState>((set, get) => ({
});
}
},
setV2Properties: (properties) => set({ v2Properties: properties }),
setV2Properties: (properties) => set({ v2Properties: properties, canDeploy:false }),
updateV2Properties: (properties) => {
const updatedProperties = { ...get().v2Properties, ...properties };
set({ v2Properties: updatedProperties, changes: get().changes + 1 });
set({ v2Properties: updatedProperties, changes: get().changes + 1, canDeploy:false });
},
setSelectedNode: (id) => {
set({
Expand Down
2 changes: 1 addition & 1 deletion keep-ui/app/workflows/builder/editors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ function WorkflowEditorV2({
}
value={properties[key] || ""as string}
/>);
case "isabled":
case "disabled":
return (
<div key={key}>
<input
Expand Down
2 changes: 1 addition & 1 deletion keep-ui/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
8 changes: 4 additions & 4 deletions keep-ui/package-lock.json

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

2 changes: 1 addition & 1 deletion keep-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
"postcss-nested": "^6.0.1",
"postcss-selector-parser": "^6.0.12",
"postcss-value-parser": "^4.2.0",
"posthog-js": "^1.161.6",
"posthog-js": "^1.163.0",
"posthog-node": "^3.1.1",
"preact-render-to-string": "^5.2.6",
"prelude-ls": "^1.2.1",
Expand Down
5 changes: 4 additions & 1 deletion keep/api/bl/enrichments_bl.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ def _check_alert_matches_rule(self, alert: AlertDto, rule: MappingRule) -> bool:
)

if not topology_service:
self.logger.warning("No topology service found to match on")
self.logger.debug(
"No topology service found to match on",
extra={"matcher_value": matcher_value},
)
else:
enrichments = topology_service.dict(exclude_none=True)
# Remove redundant fields
Expand Down
46 changes: 31 additions & 15 deletions keep/api/observability.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from urllib.parse import urlparse

from fastapi import FastAPI, Request
from opentelemetry import metrics, trace
Expand All @@ -22,37 +23,52 @@
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

def get_protocol_from_endpoint(endpoint):
parsed_url = urlparse(endpoint)
if parsed_url.scheme == "http":
return HTTPOTLPSpanExporter
elif parsed_url.scheme == "grpc":
return GRPCOTLPSpanExporter
else:
raise ValueError(f"Unsupported protocol: {parsed_url.scheme}")

def setup(app: FastAPI):
logger = logging.getLogger(__name__)
# Configure the OpenTelemetry SDK
service_name = os.environ.get("SERVICE_NAME", "keep-api")
otlp_collector_endpoint = os.environ.get("OTLP_ENDPOINT", False)
service_name = os.environ.get("OTEL_SERVICE_NAME", os.environ.get("SERVICE_NAME", "keep-api"))
otlp_collector_endpoint = os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT", os.environ.get("OTLP_ENDPOINT", False))
otlp_traces_endpoint = os.environ.get("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", None)
otlp_logs_endpoint = os.environ.get("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", None)
otlp_metrics_endpoint = os.environ.get("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", None)
enable_cloud_trace_exporeter = os.environ.get("CLOUD_TRACE_ENABLED", False)
metrics_enabled = os.environ.get("METRIC_OTEL_ENABLED", "")
# to support both grpc and http - for example dynatrace doesn't support grpc
http_or_grpc = os.environ.get("OTLP_SPAN_EXPORTER", "grpc")
if http_or_grpc == "grpc":
OTLPSpanExporter = GRPCOTLPSpanExporter
else:
OTLPSpanExporter = HTTPOTLPSpanExporter

resource = Resource.create({"service.name": service_name})
provider = TracerProvider(resource=resource)

if otlp_collector_endpoint:

logger.info(f"OTLP endpoint set to {otlp_collector_endpoint}")
processor = BatchSpanProcessor(
OTLPSpanExporter(endpoint=otlp_collector_endpoint)
)
provider.add_span_processor(processor)
if metrics_enabled.lower() == "true":
logger.info("Metrics enabled.")

if otlp_traces_endpoint:
logger.info(f"OTLP Traces endpoint set to {otlp_traces_endpoint}")
SpanExporter = get_protocol_from_endpoint(otlp_traces_endpoint)
processor = BatchSpanProcessor(
SpanExporter(endpoint=otlp_traces_endpoint)
)
provider.add_span_processor(processor)

if metrics_enabled.lower() == "true" and otlp_metrics_endpoint:
logger.info(f"Metrics enabled. OTLP Metrics endpoint set to {otlp_metrics_endpoint}")
reader = PeriodicExportingMetricReader(
OTLPMetricExporter(endpoint=otlp_collector_endpoint)
OTLPMetricExporter(endpoint=otlp_metrics_endpoint)
)
metric_provider = MeterProvider(resource=resource, metric_readers=[reader])
metrics.set_meter_provider(metric_provider)

if otlp_logs_endpoint:
logger.info(f"OTLP Logs endpoint set to {otlp_logs_endpoint}")

if enable_cloud_trace_exporeter:
logger.info("Cloud Trace exporter enabled.")
processor = BatchSpanProcessor(CloudTraceSpanExporter())
Expand Down
9 changes: 5 additions & 4 deletions keep/api/routes/preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def pull_data_from_providers(
f"Pulling alerts from provider {provider.type} ({provider.id})",
extra=extra,
)
# Even if we failed at processing some event, lets save the last pull time to not iterate this process over and over again.
update_provider_last_pull_time(tenant_id=tenant_id, provider_id=provider.id)

provider_class = ProvidersFactory.get_provider(
context_manager=context_manager,
provider_id=provider.id,
Expand All @@ -121,7 +124,8 @@ def pull_data_from_providers(
logger.info("Pulling topology data", extra=extra)
topology_data = provider_class.pull_topology()
logger.info(
"Pulling topology data finished, processing", extra=extra
"Pulling topology data finished, processing",
extra={**extra, "topology_length": len(topology_data)},
)
process_topology(
tenant_id, topology_data, provider.id, provider.type
Expand Down Expand Up @@ -155,9 +159,6 @@ def pull_data_from_providers(
f"Unknown error pulling from provider {provider.type} ({provider.id})",
extra=extra,
)
finally:
# Even if we failed at processing some event, lets save the last pull time to not iterate this process over and over again.
update_provider_last_pull_time(tenant_id=tenant_id, provider_id=provider.id)
logger.info(
"Pulling data from providers completed",
extra={
Expand Down
2 changes: 1 addition & 1 deletion keep/api/tasks/process_topology_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def process_topology(
service_id = service_to_keep_service_id_map.get(service.service)
depends_on_service_id = service_to_keep_service_id_map.get(dependency)
if not service_id or not depends_on_service_id:
logger.warning(
logger.debug(
"Found a dangling service, skipping",
extra={"service": service.service, "dependency": dependency},
)
Expand Down

0 comments on commit 48e1868

Please sign in to comment.