Skip to content

Commit

Permalink
Merge branch 'deploy/hammer' into hammer/fire-alarm
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <[email protected]>
  • Loading branch information
aaronchongth committed May 6, 2024
2 parents fd45675 + 1f14af3 commit 08351e8
Show file tree
Hide file tree
Showing 72 changed files with 2,172 additions and 1,740 deletions.
2 changes: 1 addition & 1 deletion .github/actions/bootstrap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runs:
steps:
- uses: pnpm/[email protected]
with:
version: 'latest'
version: '8.15.7'
- uses: actions/setup-node@v2
with:
node-version: '16'
Expand Down
21 changes: 0 additions & 21 deletions .github/actions/overlay/action.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/api-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ jobs:
uses: ./.github/actions/bootstrap
with:
package: api-server
- name: overlay
uses: ./.github/actions/overlay
- name: tests
run: |
. /rmf_demos_ws/install/setup.bash
. ~/hammer_overlay_ws/install/setup.bash
pnpm run lint
pnpm run test:cov
pipenv run python -m coverage xml
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/dashboard-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@
# with:
# package: rmf-dashboard-e2e
# skip-build: true
# # Somehow this step is not needed
# # - name: overlay
# # uses: ./.github/actions/overlay
# - name: test
# uses: nick-fields/retry@v2
# with:
# timeout_minutes: 20
# max_attempts: 3
# command: |
# . /rmf_demos_ws/install/setup.bash
# . ~/hammer_overlay_ws/install/setup.bash
# cd packages/dashboard-e2e
# pnpm test
# shell: bash
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/dashboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ jobs:
with:
package: rmf-dashboard
skip-build: true
- name: overlay
uses: ./.github/actions/overlay
- name: unit test
run: . /rmf_demos_ws/install/setup.bash && . ~/hammer_overlay_ws/install/setup.bash && pnpm run test:coverage
run: . /rmf_demos_ws/install/setup.bash && pnpm run test:coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ghpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ jobs:
uses: ./.github/actions/bootstrap
with:
package: api-server
- name: overlay
uses: ./.github/actions/overlay
- name: Extract docs
run: |
. /rmf_demos_ws/install/setup.bash
. ~/hammer_overlay_ws/install/setup.bash
pipenv run python3 scripts/extract_docs.py -o docs
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@ jobs:
# with:
# package: rmf-dashboard-e2e
# skip-build: true
# - name: overlay
# uses: ./.github/actions/overlay
# - name: test
# uses: nick-fields/retry@v2
# with:
# timeout_minutes: 20
# max_attempts: 3
# command: |
# . /rmf_demos_ws/install/setup.bash
# . ~/hammer_overlay_ws/install/setup.bash
# cd packages/dashboard-e2e
# pnpm test
# shell: bash
Expand Down
1,502 changes: 830 additions & 672 deletions Pipfile.lock

Large diffs are not rendered by default.

30 changes: 4 additions & 26 deletions packages/api-client/lib/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,9 @@ describe('subscriptions', () => {
spyOn(sioClient.sio, 'emit');
});

it('multiplexes subscriptions', () => {
const s1 = sioClient.subscribe('test', () => {
// empty
});
const s2 = sioClient.subscribe('test', () => {
// empty
});
expect(sioClient.sio.emit).toHaveBeenCalledOnceWith('subscribe', jasmine.anything());
(sioClient.sio.emit as jasmine.Spy).calls.reset();

sioClient.unsubscribe(s1);
sioClient.unsubscribe(s2);
expect(sioClient.sio.emit).toHaveBeenCalledOnceWith('unsubscribe', jasmine.anything());
});

it('does not unsubscribe early when there are multiple subscriptions with the same listener', () => {
const listener = jasmine.createSpy();
const s1 = sioClient.subscribe('test', listener);
const s2 = sioClient.subscribe('test', listener);
expect(sioClient.sio.emit).toHaveBeenCalledOnceWith('subscribe', jasmine.anything());
(sioClient.sio.emit as jasmine.Spy).calls.reset();

sioClient.unsubscribe(s1);
expect(sioClient.sio.emit).not.toHaveBeenCalled();
sioClient.unsubscribe(s2);
expect(sioClient.sio.emit).toHaveBeenCalledOnceWith('unsubscribe', jasmine.anything());
it('dummy', () => {
// Dummy test to ci passes.
// #940 removed multiplexing in order to support resubscribe on reconnect.
// With it gone, there is no more tests and ci fails as a result.
});
});
28 changes: 4 additions & 24 deletions packages/api-client/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,21 @@ export interface Subscription {

export class SioClient {
public sio: Socket;
private _subscriptions: Record<string, number> = {};

constructor(...args: Parameters<typeof io>) {
this.sio = io(...args);
}

subscribe<T>(room: string, listener: Listener<T>): Subscription {
const subs = this._subscriptions[room] || 0;
if (subs === 0) {
this.sio.emit('subscribe', { room });
debug(`subscribed to ${room}`);
} else {
debug(`reusing previous subscription to ${room}`);
}
this.sio.emit('subscribe', { room });
debug(`subscribed to ${room}`);
this.sio.on(room, listener);
this._subscriptions[room] = subs + 1;
return { room, listener };
}

unsubscribe(sub: Subscription): void {
const subCount = this._subscriptions[sub.room] || 0;
if (!subCount) {
debug(`tried to unsubscribe from ${sub.room}, but no subscriptions exist`);
// continue regardless
}
if (subCount <= 1) {
this.sio.emit('unsubscribe', { room: sub.room });
delete this._subscriptions[sub.room];
debug(`unsubscribed to ${sub.room}`);
} else {
this._subscriptions[sub.room] = subCount - 1;
debug(
`skipping unsubscribe to ${sub.room} because there are still ${subCount - 1} subscribers`,
);
}
this.sio.emit('unsubscribe', { room: sub.room });
debug(`unsubscribed to ${sub.room}`);
this.sio.off(sub.room, sub.listener);
}

Expand Down
154 changes: 150 additions & 4 deletions packages/api-client/lib/openapi/api.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/api-client/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { version as rmfModelVer } from 'rmf-models';

export const version = {
rmfModels: rmfModelVer,
rmfServer: '1fbe5cc4928f8ade38e2bc7d5fe18b5203eaf36d',
rmfServer: 'fd45675f94b75df6845303db4f45276d0998f3e6',
openapiGenerator: '6.2.1',
};
62 changes: 61 additions & 1 deletion packages/api-client/schema/index.ts

Large diffs are not rendered by default.

31 changes: 25 additions & 6 deletions packages/api-server/api_server/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import logging
import os

import uvicorn
import uvicorn.logging
from uvicorn.config import LOGGING_CONFIG

from .app import app
from .app_config import app_config, load_config
from .app_config import load_config
from .logging import LogfmtFormatter

app_config = load_config(
os.environ.get(
Expand All @@ -13,18 +15,35 @@
)
)

TORTOISE_ORM = app_config.get_tortoise_orm_config()
handler = logging.StreamHandler()
handler.setFormatter(LogfmtFormatter())
logging.basicConfig(level=app_config.log_level, handlers=[handler])

# uvicorn access logs contains double quotes so we need to use the safer formatter
LOGGING_CONFIG["formatters"]["logfmt"] = {"()": LogfmtFormatter}
LOGGING_CONFIG["handlers"]["logfmt"] = {
"formatter": "logfmt",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
}
# uvicorn appears to log to both the default and configured handler,
# since we already configured the default logger,
# setting a handler here will cause double logging
LOGGING_CONFIG["loggers"]["uvicorn"]["handlers"] = []
LOGGING_CONFIG["loggers"]["uvicorn.access"]["handlers"] = ["logfmt"]


def main():
LOGGING_CONFIG["formatters"]["access"][
"fmt"
] = '%(asctime)s %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s'
# FIXME: we need to init logging before the app, better solution is to
# NOT use global app that init on import
from .app import app # pylint: disable=import-outside-toplevel

uvicorn.run(
app,
host=app_config.host,
port=app_config.port,
root_path=app_config.public_url.path,
log_config=LOGGING_CONFIG,
log_level=app_config.log_level.lower(),
)

Expand Down
Loading

0 comments on commit 08351e8

Please sign in to comment.