Skip to content

Commit fd02e7c

Browse files
authored
Merge branch 'main' into provider-google-chat-add-retry-mechanism
2 parents b9cc737 + 59e7759 commit fd02e7c

File tree

20 files changed

+684
-85
lines changed

20 files changed

+684
-85
lines changed

docker/Dockerfile.api

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ RUN chgrp -R 0 /app && chmod -R g=u /app
3535
RUN chown -R keep:keep /app
3636
RUN chown -R keep:keep /venv
3737
USER keep
38-
ENTRYPOINT ["gunicorn", "keep.api.api:get_app", "--bind" , "0.0.0.0:8080" , "--workers", "4" , "-k" , "uvicorn.workers.UvicornWorker", "-c", "/venv/lib/python3.11/site-packages/keep/api/config.py"]
38+
39+
ENTRYPOINT ["/venv/lib/python3.11/site-packages/keep/entrypoint.sh"]
40+
41+
CMD ["gunicorn", "keep.api.api:get_app", "--bind" , "0.0.0.0:8080" , "--workers", "4" , "-k" , "uvicorn.workers.UvicornWorker", "-c", "/venv/lib/python3.11/site-packages/keep/api/config.py"]

docker/Dockerfile.dev.api

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ RUN . /venv/bin/activate && poetry install --no-root
2121
ENV PYTHONPATH="/app:${PYTHONPATH}"
2222
ENV PATH="/venv/bin:${PATH}"
2323
ENV VIRTUAL_ENV="/venv"
24+
ENV POSTHOG_DISABLED="true"
2425

26+
ENTRYPOINT ["/app/keep/entrypoint.sh"]
2527

2628
CMD ["gunicorn", "keep.api.api:get_app", "--bind" , "0.0.0.0:8080" , "--workers", "1" , "-k" , "uvicorn.workers.UvicornWorker", "-c", "./keep/api/config.py", "--reload"]

docs/deployment/configuration.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ General configuration variables control the core behavior of the Keep server. Th
2525
| **KEEP_API_URL** | Specifies the Keep API URL | No | Constructed from HOST and PORT | Valid URL |
2626
| **KEEP_STORE_RAW_ALERTS** | Enables storing of raw alerts | No | "false" | "true" or "false" |
2727
| **TENANT_CONFIGURATION_RELOAD_TIME** | Time in minutes to reload tenant configurations | No | 5 | Positive integer |
28+
| **KEEP_LIVE_DEMO_MODE** | Keep will simulate incoming alerts and other activity | No | "false" | "true" or "false" |
2829

2930
### Logging and Environment
3031
<Info>

keep-ui/auth.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,20 @@ const config = {
197197
}
198198
return true;
199199
},
200-
jwt: async ({ token, user, account }): Promise<JWT> => {
200+
jwt: async ({ token, user, account, profile }): Promise<JWT> => {
201201
if (account && user) {
202202
let accessToken: string | undefined;
203+
let tenantId: string | undefined = user.tenantId;
204+
let role: string | undefined = user.role;
203205
// Ensure we always have an accessToken
204206
if (authType == AuthType.AUTH0) {
205207
accessToken = account.id_token;
208+
if ((profile as any)?.keep_tenant_id) {
209+
tenantId = (profile as any).keep_tenant_id;
210+
}
211+
if ((profile as any)?.keep_role) {
212+
role = (profile as any).keep_role;
213+
}
206214
} else {
207215
accessToken =
208216
user.accessToken || account.access_token || account.id_token;
@@ -212,8 +220,8 @@ const config = {
212220
}
213221

214222
token.accessToken = accessToken;
215-
token.tenantId = user.tenantId;
216-
token.role = user.role;
223+
token.tenantId = tenantId;
224+
token.role = role;
217225

218226
if (authType === AuthType.KEYCLOAK) {
219227
token.refreshToken = account.refresh_token;

keep/api/config.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import keep.api.logging
55
from keep.api.api import AUTH_TYPE
66
from keep.api.core.db_on_start import migrate_db, try_create_single_tenant
7-
from keep.api.core.report_uptime import launch_uptime_reporting
87
from keep.api.core.dependencies import SINGLE_TENANT_UUID
98
from keep.identitymanager.identitymanagerfactory import IdentityManagerTypes
109

@@ -19,7 +18,6 @@ def on_starting(server=None):
1918
logger.info("Keep server starting")
2019

2120
migrate_db()
22-
launch_uptime_reporting()
2321

2422
# Create single tenant if it doesn't exist
2523
if AUTH_TYPE in [
@@ -54,4 +52,5 @@ def on_starting(server=None):
5452
public_url = ngrok_connection.public_url
5553
logger.info(f"ngrok tunnel: {public_url}")
5654
os.environ["KEEP_API_URL"] = public_url
55+
5756
logger.info("Keep server started")

keep/api/core/db.py

+44
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from keep.api.models.db.preset import * # pylint: disable=unused-wildcard-import
5959
from keep.api.models.db.provider import * # pylint: disable=unused-wildcard-import
6060
from keep.api.models.db.rule import * # pylint: disable=unused-wildcard-import
61+
from keep.api.models.db.system import * # pylint: disable=unused-wildcard-import
6162
from keep.api.models.db.tenant import * # pylint: disable=unused-wildcard-import
6263
from keep.api.models.db.topology import * # pylint: disable=unused-wildcard-import
6364
from keep.api.models.db.workflow import * # pylint: disable=unused-wildcard-import
@@ -4482,3 +4483,46 @@ def get_resource_ids_by_resource_type(
44824483
# Execute the query and return results
44834484
result = session.exec(query)
44844485
return result.all()
4486+
4487+
def get_or_creat_posthog_instance_id(
4488+
session: Optional[Session] = None
4489+
):
4490+
POSTHOG_INSTANCE_ID_KEY = "posthog_instance_id"
4491+
with Session(engine) as session:
4492+
system = session.exec(select(System).where(System.name == POSTHOG_INSTANCE_ID_KEY)).first()
4493+
if system:
4494+
return system.value
4495+
4496+
system = System(
4497+
id=str(uuid4()),
4498+
name=POSTHOG_INSTANCE_ID_KEY,
4499+
value=str(uuid4()),
4500+
)
4501+
session.add(system)
4502+
session.commit()
4503+
session.refresh(system)
4504+
return system.value
4505+
4506+
def get_activity_report(
4507+
session: Optional[Session] = None
4508+
):
4509+
from keep.api.models.db.user import User
4510+
4511+
last_24_hours = datetime.utcnow() - timedelta(hours=24)
4512+
activity_report = {}
4513+
with Session(engine) as session:
4514+
activity_report['tenants_count'] = session.query(Tenant).count()
4515+
activity_report['providers_count'] = session.query(Provider).count()
4516+
activity_report['users_count'] = session.query(User).count()
4517+
activity_report['last_24_hours_incidents_count'] = session.query(Incident).filter(
4518+
Incident.creation_time >= last_24_hours).count()
4519+
activity_report['last_24_hours_alerts_count'] = session.query(Alert).filter(
4520+
Alert.timestamp >= last_24_hours).count()
4521+
activity_report['last_24_hours_rules_created'] = session.query(Rule).filter(
4522+
Rule.creation_time >= last_24_hours).count()
4523+
activity_report['last_24_hours_workflows_created'] = session.query(Workflow).filter(
4524+
Workflow.creation_time >= last_24_hours).count()
4525+
activity_report['last_24_hours_workflows_executed'] = session.query(WorkflowExecution).filter(
4526+
WorkflowExecution.started >= last_24_hours).count()
4527+
4528+
return activity_report

0 commit comments

Comments
 (0)