Skip to content

Commit 4cf4a30

Browse files
committed
fix for deployment app-tendermint logging issue with the same file opened
1 parent 4b7ea9b commit 4cf4a30

File tree

40 files changed

+201
-244
lines changed

40 files changed

+201
-244
lines changed

autonomy/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@
6565
ACN_IMAGE_NAME = os.environ.get("ACN_IMAGE_NAME", "valory/open-acn-node")
6666
DEFAULT_DOCKER_IMAGE_AUTHOR = "valory"
6767
OAR_IMAGE = "{image_author}/oar-{agent}:{version}"
68-
ABSTRACT_ROUND_ABCI_SKILL_WITH_HASH = "valory/abstract_round_abci:0.1.0:bafybeifirqx2aavth5ub5wkz66l3773pzmksbftojzmha34rch4oypf5xa"
68+
ABSTRACT_ROUND_ABCI_SKILL_WITH_HASH = "valory/abstract_round_abci:0.1.0:bafybeibrsilujln5nbfd4osllzptbrrmvfez2kxrfy7sfg6mycsqphlcq4"
6969
OLAS_DOCS_URL = "https://stack.olas.network"

deployments/Dockerfiles/tendermint/app.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import shutil
2626
import stat
2727
import traceback
28+
from logging.handlers import RotatingFileHandler
2829
from pathlib import Path
2930
from typing import Any, Callable, Dict, List, Optional, Tuple, cast
3031

@@ -38,6 +39,7 @@
3839
except ImportError:
3940
from tendermint import TendermintNode, TendermintParams # type: ignore
4041

42+
DEFAULT_LOG_FILE_MAX_BYTES = 50 * 1024 * 1024 # 50MB
4143
ENCODING = "utf-8"
4244
DEFAULT_LOG_FILE = "log.log"
4345
IS_DEV_MODE = os.environ.get("DEV_MODE", "0") == "1"
@@ -50,7 +52,6 @@
5052
TM_STATUS_ENDPOINT = "http://localhost:26657/status"
5153

5254
logging.basicConfig(
53-
filename=os.environ.get("LOG_FILE", DEFAULT_LOG_FILE),
5455
level=logging.DEBUG,
5556
format="%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s", # noqa : W1309
5657
)
@@ -189,12 +190,14 @@ def dump_period(self) -> None:
189190
self.resets += 1
190191

191192

192-
def create_app( # pylint: disable=too-many-statements
193+
def create_app( # pylint: disable=too-many-statements,too-many-locals
193194
dump_dir: Optional[Path] = None,
194195
debug: bool = False,
195196
) -> Tuple[Flask, TendermintNode]:
196197
"""Create the Tendermint server app"""
197198
write_to_log = os.environ.get("WRITE_TO_LOG", "false").lower() == "true"
199+
log_file = os.environ.get("LOG_FILE", DEFAULT_LOG_FILE)
200+
198201
tendermint_params = TendermintParams(
199202
proxy_app=os.environ["PROXY_APP"],
200203
consensus_create_empty_blocks=os.environ["CREATE_EMPTY_BLOCKS"] == "true",
@@ -203,11 +206,22 @@ def create_app( # pylint: disable=too-many-statements
203206
)
204207

205208
app = Flask(__name__)
209+
app_logger = cast(logging.Logger, app.logger)
210+
211+
max_bytes = int(os.environ.get("LOG_FILE_MAX_BYTES", DEFAULT_LOG_FILE_MAX_BYTES))
212+
handler = RotatingFileHandler(log_file, maxBytes=max_bytes, backupCount=1)
213+
app_logger.addHandler(handler)
214+
215+
# if needed, tendermint logger can have a different configuration of handlers
216+
tendermint_logger = app_logger.getChild("tendermint")
217+
218+
if not write_to_log:
219+
tendermint_logger.removeHandler(handler)
220+
206221
period_dumper = PeriodDumper(logger=app.logger, dump_dir=dump_dir)
207222
tendermint_node = TendermintNode(
208223
tendermint_params,
209-
logger=app.logger,
210-
write_to_log=write_to_log,
224+
logger=tendermint_logger,
211225
)
212226
tendermint_node.init()
213227
override_config_toml()
@@ -238,18 +252,14 @@ def update_params() -> Dict:
238252

239253
try:
240254
data: Dict = json.loads(request.get_data().decode(ENCODING))
241-
cast(logging.Logger, app.logger).debug( # pylint: disable=no-member
255+
app_logger.debug( # pylint: disable=no-member
242256
f"Data update requested with data={data}"
243257
)
244258

245-
cast(logging.Logger, app.logger).info( # pylint: disable=no-member
246-
"Updating genesis config."
247-
)
259+
app_logger.info("Updating genesis config.") # pylint: disable=no-member
248260
update_genesis_config(data=data)
249261

250-
cast(logging.Logger, app.logger).info( # pylint: disable=no-member
251-
"Updating peristent peers."
252-
)
262+
app_logger.info("Updating peristent peers.") # pylint: disable=no-member
253263
config_path = Path(os.environ["TMHOME"]) / "config" / "config.toml"
254264
update_peers(
255265
validators=data["validators"],
@@ -318,13 +328,13 @@ def hard_reset() -> Tuple[Any, int]:
318328
@app.errorhandler(404) # type: ignore
319329
def handle_notfound(e: NotFound) -> Response:
320330
"""Handle server error."""
321-
cast(logging.Logger, app.logger).info(e) # pylint: disable=E
331+
app_logger.info(e) # pylint: disable=E
322332
return Response("Not Found", status=404, mimetype="application/json")
323333

324334
@app.errorhandler(500) # type: ignore
325335
def handle_server_error(e: InternalServerError) -> Response:
326336
"""Handle server error."""
327-
cast(logging.Logger, app.logger).info(e) # pylint: disable=E
337+
app_logger.info(e) # pylint: disable=E
328338
return Response("Error Closing Node", status=500, mimetype="application/json")
329339

330340
return app, tendermint_node

deployments/Dockerfiles/tendermint/tendermint.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import platform
2525
import signal
2626
import subprocess # nosec:
27-
import sys
2827
from logging import Logger
29-
from logging.handlers import RotatingFileHandler
3028
from pathlib import Path
3129
from threading import Event, Thread
3230
from typing import Any, Dict, List, Optional
@@ -37,7 +35,6 @@
3735
DEFAULT_P2P_LISTEN_ADDRESS = f"{_TCP}0.0.0.0:26656"
3836
DEFAULT_RPC_LISTEN_ADDRESS = f"{_TCP}0.0.0.0:26657"
3937
DEFAULT_TENDERMINT_LOG_FILE = "tendermint.log"
40-
DEFAULT_LOG_FILE_MAX_BYTES = 50 * 1024 * 1024 # 50MB
4138

4239

4340
class StoppableThread(
@@ -147,32 +144,18 @@ def __init__(
147144
self,
148145
params: TendermintParams,
149146
logger: Optional[Logger] = None,
150-
write_to_log: bool = False,
151147
):
152148
"""
153149
Initialize a Tendermint node.
154150
155151
:param params: the parameters.
156152
:param logger: the logger.
157-
:param write_to_log: Write to log file.
158153
"""
159154
self.params = params
160155
self._process: Optional[subprocess.Popen] = None
161156
self._monitoring: Optional[StoppableThread] = None
162157
self._stopping = False
163158
self.logger = logger or logging.getLogger()
164-
self.log_file = os.environ.get("LOG_FILE", DEFAULT_TENDERMINT_LOG_FILE)
165-
self.write_to_log = write_to_log
166-
167-
if self.write_to_log:
168-
max_bytes = int(
169-
os.environ.get("LOG_FILE_MAX_BYTES", DEFAULT_LOG_FILE_MAX_BYTES)
170-
)
171-
handler = RotatingFileHandler(
172-
self.log_file, maxBytes=max_bytes, backupCount=1
173-
)
174-
handler.setFormatter(logging.Formatter("%(message)s"))
175-
self.logger.addHandler(handler)
176159

177160
def _build_init_command(self) -> List[str]:
178161
"""Build the 'init' command."""
@@ -299,17 +282,9 @@ def stop(self) -> None:
299282
self._stop_tm_process()
300283
self._stop_monitoring_thread()
301284

302-
@staticmethod
303-
def _write_to_console(line: str) -> None:
304-
"""Write line to console."""
305-
sys.stdout.write(str(line))
306-
sys.stdout.flush()
307-
308285
def log(self, line: str) -> None:
309286
"""Open and write a line to the log file."""
310-
self._write_to_console(line=line)
311-
if self.write_to_log:
312-
self.logger.info(line.strip())
287+
self.logger.info(line.strip())
313288

314289
def prune_blocks(self) -> int:
315290
"""Prune blocks from the Tendermint state"""

docs/api/connections/abci/connection.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,7 @@ A class to manage a Tendermint node.
786786
#### `__`init`__`
787787

788788
```python
789-
def __init__(params: TendermintParams,
790-
logger: Optional[Logger] = None,
791-
write_to_log: bool = False)
789+
def __init__(params: TendermintParams, logger: Optional[Logger] = None)
792790
```
793791

794792
Initialize a Tendermint node.
@@ -797,7 +795,6 @@ Initialize a Tendermint node.
797795

798796
- `params`: the parameters.
799797
- `logger`: the logger.
800-
- `write_to_log`: Write to log file.
801798

802799
<a id="packages.valory.connections.abci.connection.TendermintNode.init"></a>
803800

docs/counter_example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ you have followed the [setup instructions](guides/quick_start.md#setup). As a re
2525

2626
2. Use the CLI to download the `valory/counter` service.
2727
```bash
28-
autonomy fetch valory/counter:0.1.0:bafybeielwb4td4oc5atfhws45g7zwowopctsm3zwon4qkdtpsk4p7lfpau --remote --service
28+
autonomy fetch valory/counter:0.1.0:bafybeihvivyinyymbim5tmwmptqibehmlph24xzdrcju7ysonj4b2o7l3i --remote --service
2929
cd counter
3030
```
3131

@@ -284,7 +284,7 @@ First, open a terminal to the root of this repository,
284284
and fetch the `counter_client` agent:
285285
286286
```bash
287-
autonomy fetch valory/counter_client:0.1.0:bafybeiclm7j5tod2rwm5qtyzxh5rdr7xojyajdf6o7emr2ym3ucofzrifa --remote
287+
autonomy fetch valory/counter_client:0.1.0:bafybeichn562aulrez6pmslfptwp7udurqec2hkbo5fskhn6jkianigttu --remote
288288
```
289289
290290
This will copy the agent project in the `counter_client` directory.

docs/guides/overview_of_the_development_process.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ To follow the next sections, you need to populate the local registry with a numb
3232
"third_party": {
3333
"service/valory/hello_world/0.1.0": "bafybeicj73kflta5sfxq7gnnk7smcdp2gwcfvfvm2plxc5ojhulwa3xnoq",
3434
"agent/valory/hello_world/0.1.0": "bafybeig2mv6afojsype4v2fwkpzkvdohbeg6ilvp2tokn7i6ub2csd6wxi",
35-
"connection/valory/abci/0.1.0": "bafybeiajrsgli7r5ouxydfzk42monl44c4av3jnys3oezgmg7ye4xk5sla",
36-
"connection/valory/http_client/0.23.0": "bafybeidmlazrjbnn5mw4wxrrj7lfnci7amt5alke2ahb3yirac6qudxuwm",
35+
"connection/valory/abci/0.1.0": "bafybeifglhfcyakotc34xeryjsqpdvcub3cljeoa2ncbw7fqgotaru4d2m",
36+
"connection/valory/http_client/0.23.0": "bafybeihi772xgzpqeipp3fhmvpct4y6e6tpjp4sogwqrnf3wqspgeilg4u",
3737
"connection/valory/ipfs/0.1.0": "bafybeie3uryd4ccavzjd5ujsndjaqxz4gu3ka2scwvvqadcesciuohnuue",
38-
"connection/valory/ledger/0.19.0": "bafybeicoc67atvjzld5e7qzbdkc7c2fj5jrtuj77nx6igxcdxqqqwxiduy",
38+
"connection/valory/ledger/0.19.0": "bafybeiak6qbhmvvlx67cb4asts4qis524j3afyv5uqypmuzrp7txp5maiq",
3939
"contract/valory/service_registry/0.1.0": "bafybeici5pqtcuiyytasf3yma6kbmol3p25wmylrxrm2orsr3deyoeuodu",
40-
"protocol/open_aea/signing/1.0.0": "bafybeierdeo55vv7nxdag3s2kk6gh4essmeeqpa7vperbw3wn3ypzmtcdm",
40+
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
4141
"protocol/valory/abci/0.1.0": "bafybeigdi6wsbdn2nv7clzhnuhki3taywgiiajwawdaat57o5ntlgqj2qe",
42-
"protocol/valory/acn/1.1.0": "bafybeihouwpsgkbafgsfdcwiwhz3smrjuw24b74j4v3n3hxirmxeskldwq",
43-
"protocol/valory/contract_api/1.0.0": "bafybeigv273fllpdsmzip4qfmhyvltdcss4yhoicss32c2yc7am6kue4cy",
44-
"protocol/valory/http/1.0.0": "bafybeia43es3r7haqhdcx4f3uwfcreeytyk4zadczsafwyc5dzwr7lu2jq",
42+
"protocol/valory/acn/1.1.0": "bafybeidluaoeakae3exseupaea4i3yvvk5vivyt227xshjlffywwxzcxqe",
43+
"protocol/valory/contract_api/1.0.0": "bafybeidgu7o5llh26xp3u3ebq3yluull5lupiyeu6iooi2xyymdrgnzq5i",
44+
"protocol/valory/http/1.0.0": "bafybeifugzl63kfdmwrxwphrnrhj7bn6iruxieme3a4ntzejf6kmtuwmae",
4545
"protocol/valory/ipfs/0.1.0": "bafybeib7jhgyocjwdq3r5wzq3z4qeubj3dwi3aqjn2uxzuwnjp5fhvafcu",
46-
"protocol/valory/ledger_api/1.0.0": "bafybeifvbahdmabpswhu45q6xb2jppbvqlfztya6jx2ttu4eb6pjltyxam",
46+
"protocol/valory/ledger_api/1.0.0": "bafybeihdk6psr4guxmbcrc26jr2cbgzpd5aljkqvpwo64bvaz7tdti2oni",
4747
"protocol/valory/tendermint/0.1.0": "bafybeif5wq5i2ugr66alniej2bk4vws5sikal7otx674y5kz52e3ulo2qm",
48-
"skill/valory/abstract_abci/0.1.0": "bafybeihgbihz5wlimwnslwwp35w4bjkg3bdhnhbfwwpfoojssibluvl3b4",
49-
"skill/valory/abstract_round_abci/0.1.0": "bafybeifirqx2aavth5ub5wkz66l3773pzmksbftojzmha34rch4oypf5xa",
48+
"skill/valory/abstract_abci/0.1.0": "bafybeihqy6dizr72a4q2eu42jnjwjonq4dxvvqhvw2xgsn5lzsbha55ybq",
49+
"skill/valory/abstract_round_abci/0.1.0": "bafybeibrsilujln5nbfd4osllzptbrrmvfez2kxrfy7sfg6mycsqphlcq4",
5050
"skill/valory/hello_world_abci/0.1.0": "bafybeihmpphbsrr5niduaf3r2jzqjjoip5ep5aynphxfoqqqdzmkwobwyi",
51-
"connection/valory/p2p_libp2p_client/0.1.0": "bafybeihiulggi4jz3i7qdjicztbvlrkesyb7paiovfcmw22xvovpweeq7y"
51+
"connection/valory/p2p_libp2p_client/0.1.0": "bafybeid3xg5k2ol5adflqloy75ibgljmol6xsvzvezebsg7oudxeeolz7e"
5252
}
5353
}
5454
```

0 commit comments

Comments
 (0)