Skip to content

Commit 2b98125

Browse files
authored
Merge pull request #151 from devsapp/fix/logs-multi-topic-and-query-syntax
fix: logs command multi-topic search and SLS field query syntax
2 parents ddf7009 + f634129 commit 2b98125

9 files changed

Lines changed: 254 additions & 42 deletions

File tree

.github/workflows/ci_node16.yaml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ jobs:
1919
macos-ci:
2020
runs-on: macos-latest
2121
steps:
22-
- uses: actions/checkout@v2
23-
- uses: actions/setup-node@v2
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-node@v4
2424
with:
2525
node-version: 16
2626
registry-url: https://registry.npmjs.org/
@@ -29,9 +29,10 @@ jobs:
2929
with:
3030
go-version: 1.18
3131
- name: Set up Java
32-
uses: actions/setup-java@v1
32+
uses: actions/setup-java@v4
3333
with:
3434
java-version: 8
35+
distribution: zulu
3536
- name: install s
3637
run: |
3738
npm i @serverless-devs/s -g
@@ -58,8 +59,8 @@ jobs:
5859
windows-ci:
5960
runs-on: windows-latest
6061
steps:
61-
- uses: actions/checkout@v2
62-
- uses: actions/setup-node@v2
62+
- uses: actions/checkout@v4
63+
- uses: actions/setup-node@v4
6364
with:
6465
node-version: 16
6566
registry-url: https://registry.npmjs.org/
@@ -71,9 +72,10 @@ jobs:
7172
with:
7273
go-version: 1.18
7374
- name: Set up Java
74-
uses: actions/setup-java@v1
75+
uses: actions/setup-java@v4
7576
with:
7677
java-version: 8
78+
distribution: zulu
7779
- name: install s
7880
run: |
7981
npm i @serverless-devs/s -g
@@ -102,8 +104,8 @@ jobs:
102104
linux-ci:
103105
runs-on: ubuntu-latest
104106
steps:
105-
- uses: actions/checkout@v2
106-
- uses: actions/setup-node@v2
107+
- uses: actions/checkout@v4
108+
- uses: actions/setup-node@v4
107109
with:
108110
node-version: 16
109111
registry-url: https://registry.npmjs.org/
@@ -112,9 +114,10 @@ jobs:
112114
with:
113115
go-version: 1.18
114116
- name: Set up Java
115-
uses: actions/setup-java@v1
117+
uses: actions/setup-java@v4
116118
with:
117119
java-version: 8
120+
distribution: zulu
118121
- name: install s
119122
run: |
120123
npm i @serverless-devs/s -g

.github/workflows/ci_with_docker_linux.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
docker-ci-standard:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616
- uses: docker/setup-buildx-action@v2
17-
- uses: actions/setup-node@v2
17+
- uses: actions/setup-node@v4
1818
with:
1919
node-version: 16
2020
registry-url: https://registry.npmjs.org/
@@ -23,9 +23,10 @@ jobs:
2323
with:
2424
go-version: 1.18
2525
- name: Set up Java
26-
uses: actions/setup-java@v1
26+
uses: actions/setup-java@v4
2727
with:
2828
java-version: 8
29+
distribution: zulu
2930
- name: Install dependencies
3031
run: |
3132
sudo apt-get update
@@ -68,9 +69,9 @@ jobs:
6869
docker-ci-custom:
6970
runs-on: ubuntu-latest
7071
steps:
71-
- uses: actions/checkout@v2
72+
- uses: actions/checkout@v4
7273
- uses: docker/setup-buildx-action@v2
73-
- uses: actions/setup-node@v2
74+
- uses: actions/setup-node@v4
7475
with:
7576
node-version: 16
7677
registry-url: https://registry.npmjs.org/
@@ -79,9 +80,10 @@ jobs:
7980
with:
8081
go-version: 1.18
8182
- name: Set up Java
82-
uses: actions/setup-java@v1
83+
uses: actions/setup-java@v4
8384
with:
8485
java-version: 8
86+
distribution: zulu
8587
- name: Install dependencies
8688
run: |
8789
sudo apt-get update

CLAUDE.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Claude Code Configuration
2+
3+
This file contains configuration information for Claude Code, an AI programming assistant.
4+
5+
## Project Overview
6+
7+
FC3 is the Serverless Devs component for Alibaba Cloud Function Compute 3.0, providing full lifecycle management for serverless functions. Written in TypeScript with modular architecture supporting create, develop, debug, deploy, and operate workflows.
8+
9+
**Tech Stack**: TypeScript 4.4, Jest, Vercel ncc, f2elint, Prettier
10+
11+
## Available Scripts
12+
13+
| Script | Description |
14+
| ------------------------- | -------------------------- |
15+
| `npm run build` | Production bundle with ncc |
16+
| `npm run watch` | TypeScript watch mode |
17+
| `npm test` | Jest tests with coverage |
18+
| `npm run format` | Prettier formatting |
19+
| `npm run lint` | f2elint scanning |
20+
| `npm run fix` | Auto-fix lint issues |
21+
| `npm run publish` | Build and registry publish |
22+
| `npm run generate-schema` | Generate JSON schema |
23+
24+
## Key Directories
25+
26+
| Directory | Purpose |
27+
| ------------------ | -------------------------------------------- |
28+
| `src/` | Source code |
29+
| `src/subCommands/` | CLI subcommands (deploy, build, local, etc.) |
30+
| `src/resources/` | Cloud resources (FC, RAM, SLS, OSS, ACR) |
31+
| `src/interface/` | TypeScript interfaces |
32+
| `src/utils/` | Utility functions |
33+
| `__tests__/ut/` | Unit tests |
34+
| `__tests__/it/` | Integration tests |
35+
| `docs/` | Documentation |
36+
37+
## Testing
38+
39+
**Current Status**: 986 tests total, 986 passing, 2 skipped (integration tests require cloud credentials)
40+
41+
**Run tests**: `npm test`
42+
**Coverage**: Run with `--coverage` flag
43+
44+
## Architecture
45+
46+
Modular architecture with:
47+
48+
1. Main entry (`index.ts`) routing to subcommands
49+
2. Base class (`base.ts`) with common preprocessing
50+
3. Subcommand modules for operations
51+
4. Resource modules for cloud service integration
52+
53+
See `docs/architecture.md` for detailed diagrams.
54+
55+
## Recent Features
56+
57+
- HTTP URL support for code/layer sources (v0.1.17)
58+
- Layer publish HTTP bug fix (PR #147)
59+
- FileManager remove operation upgrade support
60+
- ProvisionConfig/ScalingConfig array handling
61+
- LLM metrics in logConfig
62+
- Logs command: multi-topic search (FCLogs + FCInstanceEvents) for --instance-id, SLS field-specific query syntax
63+
64+
## Development Workflow
65+
66+
1. Create branch from `master`
67+
2. Run `npm run lint` and `npm run format`
68+
3. Write/update tests
69+
4. Build: `npm run build`
70+
5. Test: `npm test`
71+
6. Submit PR
72+
73+
## Documentation Index
74+
75+
| File | Purpose |
76+
| ---------------------- | -------------------- |
77+
| `docs/CONTRIB.md` | Development guide |
78+
| `docs/RUNBOOK.md` | Operations runbook |
79+
| `docs/architecture.md` | Architecture details |

__tests__/ut/commands/logs_test.ts

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,13 @@ describe('Logs', () => {
177177
projectName: 'test-project',
178178
logStoreName: 'test-logstore',
179179
topic: 'FCLogs:test-function',
180+
topicFilter: '__topic__:"FCLogs:test-function"',
180181
query: '',
181182
search: '',
182183
qualifier: '',
183184
match: '',
185+
requestId: '',
186+
instanceId: '',
184187
};
185188
// Call the single iteration method
186189
await this._realtimeOnce(params);
@@ -212,6 +215,8 @@ describe('Logs', () => {
212215
projectName: 'test-project',
213216
logStoreName: 'test-logstore',
214217
topic: 'FCLogs:test-function',
218+
topicFilter: '__topic__:"FCLogs:test-function"',
219+
functionName: 'test-function',
215220
}),
216221
);
217222
});
@@ -244,8 +249,29 @@ describe('Logs', () => {
244249
const props = await (logs as any).getInputs();
245250

246251
expect(props.topic).toBe('test-function');
252+
expect(props.topicFilter).toBe('__topic__:"test-function"');
247253
expect(props.query).toBe('LATEST');
248254
});
255+
256+
it('should include FCInstanceEvents topic when instance-id is specified', async () => {
257+
mockInputs.args = ['--instance-id', 'c-69f8a959-15f8e4fe-b867da209124'];
258+
logs = new Logs(mockInputs);
259+
260+
const props = await (logs as any).getInputs();
261+
262+
expect(props.topicFilter).toBe(
263+
'(__topic__:"FCLogs:test-function" or __topic__:"FCInstanceEvents:/test-function")',
264+
);
265+
});
266+
267+
it('should not unset LATEST qualifier', async () => {
268+
mockInputs.args = ['--qualifier', 'LATEST'];
269+
logs = new Logs(mockInputs);
270+
271+
const props = await (logs as any).getInputs();
272+
273+
expect(props.qualifier).toBe('LATEST');
274+
});
249275
});
250276

251277
describe('getFunction', () => {
@@ -291,6 +317,7 @@ describe('Logs', () => {
291317
projectName: 'test-project',
292318
logStoreName: 'test-logstore',
293319
topic: 'FCLogs:test-function',
320+
topicFilter: '__topic__:"FCLogs:test-function"',
294321
query: '',
295322
search: '',
296323
type: '',
@@ -299,6 +326,7 @@ describe('Logs', () => {
299326
qualifier: '',
300327
startTime: '',
301328
endTime: '',
329+
functionName: 'test-function',
302330
};
303331

304332
const result = await (logs as any).history(params);
@@ -318,6 +346,7 @@ describe('Logs', () => {
318346
projectName: 'test-project',
319347
logStoreName: 'test-logstore',
320348
topic: 'FCLogs:test-function',
349+
topicFilter: '__topic__:"FCLogs:test-function"',
321350
query: '',
322351
search: '',
323352
type: '',
@@ -326,6 +355,7 @@ describe('Logs', () => {
326355
qualifier: '',
327356
startTime: '2023-01-01T00:00:00Z',
328357
endTime: '2023-01-01T01:00:00Z',
358+
functionName: 'test-function',
329359
};
330360

331361
const result = await (logs as any).history(params);
@@ -338,6 +368,7 @@ describe('Logs', () => {
338368
projectName: 'test-project',
339369
logStoreName: 'test-logstore',
340370
topic: 'FCLogs:test-function',
371+
topicFilter: '__topic__:"FCLogs:test-function"',
341372
query: '',
342373
search: '',
343374
type: '',
@@ -346,6 +377,7 @@ describe('Logs', () => {
346377
qualifier: '',
347378
startTime: 'invalid-date',
348379
endTime: 'also-invalid',
380+
functionName: 'test-function',
349381
};
350382

351383
await expect((logs as any).history(params)).rejects.toThrow(
@@ -367,10 +399,13 @@ describe('Logs', () => {
367399
projectName: 'test-project',
368400
logStoreName: 'test-logstore',
369401
topic: 'FCLogs:test-function',
402+
topicFilter: '__topic__:"FCLogs:test-function"',
370403
query: '',
371404
search: '',
372405
qualifier: '',
373406
match: '',
407+
requestId: '',
408+
instanceId: '',
374409
};
375410

376411
// We'll only run one iteration in the test
@@ -526,9 +561,12 @@ describe('Logs', () => {
526561
'LATEST',
527562
'req-123',
528563
'inst-456',
564+
'__topic__:"FCLogs:test-function"',
529565
);
530566

531-
expect(result).toBe('baseQuery and searchTerm and LATEST and inst-456 and req-123');
567+
expect(result).toBe(
568+
'__topic__:"FCLogs:test-function" and baseQuery and searchTerm and qualifier: "LATEST" and instanceID: "inst-456" and requestId: "req-123"',
569+
);
532570
});
533571

534572
it('should generate SLS query with some parameters', () => {
@@ -542,6 +580,47 @@ describe('Logs', () => {
542580

543581
expect(result).toBe('');
544582
});
583+
584+
it('should generate topicFilter with FCInstanceEvents when instanceId is specified', () => {
585+
const result = (logs as any).getSlsQuery(
586+
null,
587+
null,
588+
null,
589+
null,
590+
'inst-456',
591+
'(__topic__:"FCLogs:test-function" or __topic__:"FCInstanceEvents:/test-function")',
592+
);
593+
594+
expect(result).toBe(
595+
'(__topic__:"FCLogs:test-function" or __topic__:"FCInstanceEvents:/test-function") and instanceID: "inst-456"',
596+
);
597+
});
598+
599+
it('should generate query with topicFilter only', () => {
600+
const result = (logs as any).getSlsQuery(
601+
null,
602+
null,
603+
null,
604+
null,
605+
null,
606+
'__topic__:"FCLogs:test-function"',
607+
);
608+
609+
expect(result).toBe('__topic__:"FCLogs:test-function"');
610+
});
611+
612+
it('should use field-specific syntax for qualifier', () => {
613+
const result = (logs as any).getSlsQuery(
614+
null,
615+
null,
616+
'LATEST',
617+
null,
618+
null,
619+
'__topic__:"FCLogs:test-function"',
620+
);
621+
622+
expect(result).toBe('__topic__:"FCLogs:test-function" and qualifier: "LATEST"');
623+
});
545624
});
546625

547626
describe('compareLogConfig', () => {

docs/architecture.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ src/
243243
- **核心功能**:
244244
- 项目名称生成
245245
- 日志存储名称生成
246+
- SLS 查询语句生成(支持字段查询语法)
247+
- 多 topic 搜索(FCLogs、FCInstanceEvents)
246248

247249
#### 4.4 VPC-NAS 网络存储 (vpc-nas/)
248250

0 commit comments

Comments
 (0)