-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into deprecate-topic-partitions-count
- Loading branch information
Showing
14 changed files
with
292 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ PyYAML==6.0 | |
sqlparse==0.4.2 | ||
google-api-python-client==2.88.0 | ||
sentry-usage-accountant==0.0.10 | ||
freezegun==1.2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
snuba/admin/static/auto_replacements_bypass_projects/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { AutoReplacementsBypassProjectsData } from "SnubaAdmin/auto_replacements_bypass_projects/types"; | ||
|
||
import Client from "SnubaAdmin/api_client"; | ||
import { Table } from "../table"; | ||
|
||
function AutoReplacementsBypassProjects(props: { api: Client }) { | ||
const [data, setData] = useState<AutoReplacementsBypassProjectsData[] | null>( | ||
null | ||
); | ||
|
||
useEffect(() => { | ||
props.api.getAutoReplacementsBypassProjects().then((res) => { | ||
setData(res); | ||
}); | ||
}, []); | ||
|
||
if (!data) { | ||
return null; | ||
} | ||
|
||
const rowData = data.map(({ projectID, expiry }) => { | ||
return [projectID, expiry]; | ||
}); | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<Table | ||
headerData={["Project ID", "Expiration Time"]} | ||
rowData={rowData} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default AutoReplacementsBypassProjects; |
8 changes: 8 additions & 0 deletions
8
snuba/admin/static/auto_replacements_bypass_projects/types.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ReactNode } from "react"; | ||
|
||
type AutoReplacementsBypassProjectsData = { | ||
projectID: number; | ||
expiry: string; | ||
}; | ||
|
||
export { AutoReplacementsBypassProjectsData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
import typing | ||
from datetime import datetime, timedelta | ||
from typing import Mapping, Sequence | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
from snuba.redis import RedisClientKey, get_redis_client | ||
from snuba.state import get_int_config | ||
|
||
redis_client = get_redis_client(RedisClientKey.REPLACEMENTS_STORE) | ||
config_auto_replacements_bypass_projects_hash = ( | ||
"snuba-config-auto-replacements-bypass-projects-hash" | ||
) | ||
|
||
REPLACEMENTS_EXPIRY_WINDOW_MINUTES_KEY = "replacements_expiry_window_minutes" | ||
|
||
|
||
def set_config_auto_replacements_bypass_projects( | ||
new_project_ids: Sequence[int], curr_time: datetime | ||
) -> None: | ||
try: | ||
projects_within_expiry = get_config_auto_replacements_bypass_projects(curr_time) | ||
expiry_window = typing.cast( | ||
int, get_int_config(key=REPLACEMENTS_EXPIRY_WINDOW_MINUTES_KEY, default=5) | ||
) | ||
pipeline = redis_client.pipeline() | ||
for project_id in new_project_ids: | ||
if project_id not in projects_within_expiry: | ||
expiry = curr_time + timedelta(minutes=expiry_window) | ||
pipeline.hset( | ||
config_auto_replacements_bypass_projects_hash, | ||
project_id, | ||
expiry.isoformat(), | ||
) | ||
pipeline.execute() | ||
except Exception as e: | ||
logger.exception(e) | ||
|
||
|
||
def _retrieve_projects_from_redis() -> Mapping[int, datetime]: | ||
try: | ||
return { | ||
int(k.decode("utf-8")): datetime.fromisoformat(v.decode("utf-8")) | ||
for k, v in redis_client.hgetall( | ||
config_auto_replacements_bypass_projects_hash | ||
).items() | ||
} | ||
except Exception as e: | ||
logger.exception(e) | ||
return {} | ||
|
||
|
||
def get_config_auto_replacements_bypass_projects( | ||
curr_time: datetime, | ||
) -> Mapping[int, datetime]: | ||
curr_projects = _retrieve_projects_from_redis() | ||
|
||
valid_projects = {} | ||
pipeline = redis_client.pipeline() | ||
for project_id in curr_projects: | ||
if curr_projects[project_id] < curr_time: | ||
pipeline.hdel(config_auto_replacements_bypass_projects_hash, project_id) | ||
else: | ||
valid_projects[project_id] = curr_projects[project_id] | ||
pipeline.execute() | ||
|
||
return valid_projects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.