Skip to content

Commit bf2792f

Browse files
authored
A "re-imagining" of the old pbench-reindex (distributed-system-analysis#3614)
* A "re-imagining" of the old `pbench-reindex` This supports deleting a datasets's indexed data and triggering re-indexing. It also provides a mechanism to globally enable or disable indexing. In the short term, this provides a workaround for our sharding issues, which are preventing us from generating useful indexing anyway, by turning it off entirely for new datasets. We can also delete indexed data (and the SQL index maps) for existing datasets and, on demand, trigger re-indexing for selected datasets.
1 parent 12710f1 commit bf2792f

File tree

13 files changed

+481
-14
lines changed

13 files changed

+481
-14
lines changed

lib/pbench/cli/server/__init__.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import datetime
22
from threading import Thread
33
import time
4+
from typing import Any, Optional
45

56
import click
7+
from click import Context, Parameter, ParamType
8+
from dateutil import parser
69

710
from pbench.server import PbenchServerConfig
811
from pbench.server.database import init_db
@@ -30,13 +33,13 @@ def __bool__(self) -> bool:
3033
return self.detail
3134

3235
def error(self, message: str):
33-
"""Write a message if details are enabled.
36+
"""Write an error message if error details are enabled.
3437
3538
Args:
3639
message: Detail string
3740
"""
3841
if self.errors:
39-
click.secho(f"|| {message}", fg="red")
42+
click.secho(f"|E| {message}", fg="red", err=True)
4043

4144
def message(self, message: str):
4245
"""Write a message if details are enabled.
@@ -45,7 +48,16 @@ def message(self, message: str):
4548
message: Detail string
4649
"""
4750
if self.detail:
48-
click.echo(f"|| {message}")
51+
click.echo(f"|I| {message}")
52+
53+
def warning(self, message: str):
54+
"""Write a warning message if error details are enabled.
55+
56+
Args:
57+
message: Detail string
58+
"""
59+
if self.errors:
60+
click.secho(f"|W| {message}", fg="blue", err=True)
4961

5062

5163
class Verify:
@@ -75,7 +87,7 @@ def status(self, message: str):
7587
"""
7688
if self.verify:
7789
ts = datetime.datetime.now().astimezone()
78-
click.secho(f"({ts:%H:%M:%S}) {message}", fg="green")
90+
click.secho(f"({ts:%H:%M:%S}) {message}", fg="green", err=True)
7991

8092

8193
class Watch:
@@ -120,10 +132,33 @@ def watcher(self):
120132
hours, remainder = divmod(delta, 3600)
121133
minutes, seconds = divmod(remainder, 60)
122134
click.secho(
123-
f"[{hours:02d}:{minutes:02d}:{seconds:02d}] {self.status}", fg="cyan"
135+
f"[{hours:02d}:{minutes:02d}:{seconds:02d}] {self.status}",
136+
fg="cyan",
137+
err=True,
124138
)
125139

126140

141+
class DateParser(ParamType):
142+
"""The DateParser type converts date strings into `datetime` objects.
143+
144+
This is a variant of click's built-in DateTime parser, but uses the
145+
more flexible dateutil.parser
146+
"""
147+
148+
name = "dateparser"
149+
150+
def convert(
151+
self, value: Any, param: Optional[Parameter], ctx: Optional[Context]
152+
) -> Any:
153+
if isinstance(value, datetime.datetime):
154+
return value
155+
156+
try:
157+
return parser.parse(value)
158+
except Exception as e:
159+
self.fail(f"{value!r} cannot be converted to a datetime: {str(e)!r}")
160+
161+
127162
def config_setup(context: object) -> PbenchServerConfig:
128163
config = PbenchServerConfig.create(context.config)
129164
# We're going to need the DB to track dataset state, so setup DB access.

0 commit comments

Comments
 (0)