Skip to content

Commit 731bc89

Browse files
authored
Add CI, linter and license checkers (#17)
1. Add initial CI to cover lint, license check, DLC 2. Enforce coding style 3. Update dependency and provide commands to fix code smell
1 parent 617c819 commit 731bc89

18 files changed

+1767
-2537
lines changed

Diff for: .dlc.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"ignorePatterns": [
3+
{
4+
"pattern": "^http://localhost"
5+
}
6+
],
7+
"timeout": "10s",
8+
"retryOn429": true,
9+
"retryCount": 10,
10+
"fallbackRetryDelay": "1000s",
11+
"aliveStatusCodes": [
12+
200,
13+
401,
14+
403
15+
]
16+
}

Diff for: .github/workflows/CI.yaml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2022 SkyAPM org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: CI
16+
17+
on:
18+
pull_request:
19+
push:
20+
branches:
21+
- master
22+
schedule:
23+
- cron: '0 18 * * *'
24+
25+
concurrency:
26+
group: CI-${{ github.event.pull_request.number || github.ref }}
27+
cancel-in-progress: true
28+
29+
jobs:
30+
license-and-lint:
31+
name: License and Lint
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout source codes
35+
uses: actions/checkout@v3
36+
with:
37+
submodules: true
38+
- name: Check License
39+
uses: apache/skywalking-eyes/header@442d4621d10ae9e92a859d873e6e63664622a50d
40+
- name: Set up Python
41+
uses: actions/setup-python@v3
42+
with:
43+
python-version: '3.10'
44+
- name: Python Linters
45+
run: |
46+
pip install -U pip setuptools
47+
pip install poetry
48+
make lint

Diff for: .github/workflows/dead-link-checker.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2022 SkyAPM org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Dead link checker is always run on all files
16+
name: Dead Link Checker
17+
18+
on:
19+
pull_request:
20+
push:
21+
branches:
22+
- master
23+
schedule:
24+
- cron: '0 18 * * *'
25+
26+
concurrency:
27+
group: dlc-${{ github.event.pull_request.number || github.ref }}
28+
cancel-in-progress: true
29+
30+
jobs:
31+
CheckDeadLinks:
32+
runs-on: ubuntu-latest
33+
timeout-minutes: 30
34+
if: (github.event_name == 'schedule' && github.repository == 'SkyAPM/aiops-engine-for-skywalking') || (github.event_name != 'schedule')
35+
steps:
36+
- uses: actions/checkout@v3
37+
- uses: gaurav-nelson/github-action-markdown-link-check@v1
38+
with:
39+
use-quiet-mode: 'no'
40+
use-verbose-mode: 'yes'
41+
config-file: '.dlc.json'
42+
folder-path: 'docs/'

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ dist/
2323
**/*.egg-info/
2424
**/*venv*/
2525
.vscode/
26+
engine_protocol/
27+
assets/datasets

Diff for: .licenserc.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2022 SkyAPM org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
header:
16+
license:
17+
spdx-id: Apache-2.0
18+
copyright-owner: SkyAPM org
19+
20+
paths-ignore:
21+
- 'dist'
22+
- '**/*.md'
23+
- 'LICENSE'
24+
- 'NOTICE'
25+
- '.github/*_TEMPLATE'
26+
- '.gitignore'
27+
- '**/*.json'
28+
- '**/*.ipynb'
29+
- '**/*.lock'
30+
- '**/*.csv'
31+
32+
comment: on-failure

Diff for: Makefile

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2022 SkyAPM org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
VERSION ?= latest
16+
17+
# determine host platform
18+
VENV_DIR = .venv
19+
VENV = $(VENV_DIR)/bin
20+
ifeq ($(OS),Windows_NT)
21+
VENV=./$(VENV_DIR)/Scripts
22+
endif
23+
24+
$(VENV):
25+
python3 -m venv $(VENV_DIR)
26+
poetry run python -m pip install --upgrade pip
27+
28+
all: gen get-dataset prune-dataset lint license clean
29+
30+
.PHONY: all
31+
32+
gen:
33+
poetry run python -m pip install grpcio-tools
34+
poetry run python -m tools.grpc_code_gen
35+
36+
#argument indicates a dataset name defined in sample_data_manager.py
37+
get-dataset:
38+
poetry run python -m tools.sample_data_manager download --name $(name) --save $(save)
39+
prune-dataset: # remove all downloaded datasets
40+
poetry run python -m tools.sample_data_manager clean --purge
41+
42+
# flake8 configurations should go to the file setup.cfg
43+
44+
lint-setup:
45+
poetry install --only linters
46+
47+
lint: lint-setup
48+
poetry run python -m flake8
49+
50+
# fix problems described in CodingStyle.md - verify outcome with extra care
51+
lint-fix: lint-setup
52+
$(VENV)/isort .
53+
$(VENV)/unify -r --in-place .
54+
$(VENV)/flynt -tc -v .
55+
56+
# todo make this work on windows
57+
clean:
58+
find . -name "*.egg-info" -exec rm -r {} +
59+
find . -name "dist" -exec rm -r {} +
60+
find . -name "build" -exec rm -r {} +
61+
find . -name "__pycache__" -exec rm -r {} +
62+
find . -name ".pytest_cache" -exec rm -r {} +
63+
find . -name "*.pyc" -exec rm -r {} +

Diff for: docs/en/contribute/CodingStyle.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Coding Style for the SkyWalking AIOps Engine
2+
3+
## String formatting
4+
5+
Since Python 3.5 is end of life, we fully utilize the clarity and performance boost brought
6+
by [f-strings](https://docs.python.org/3/reference/lexical_analysis.html#f-strings).
7+
Please do not use other styles - `+`, `%` or `.format` unless f-string is absolutely unfeasible in the context, or
8+
it is a logger message, which is [optimized](https://docs.python.org/3/howto/logging.html#optimization) for the `%`
9+
style
10+
11+
Run `make lint-fix` to invoke [flynt](https://github.com/ikamensh/flynt) to convert other formats to f-string, pay **
12+
extra care** to possible corner
13+
cases leading to a semantically different conversion.
14+
15+
### Quotes
16+
17+
As we know both single quotes and double quotes are both acceptable in Python.
18+
For a better coding style, we enforce a check for using single quotes when possible.
19+
20+
Please only use double quotes on the outside when there are inevitable single quotes inside the string, or when there
21+
are nest quotes.
22+
23+
For example -
24+
25+
```python
26+
foo = f"I'm a string"
27+
bar = f"This repo is called 'skywalking-python'"
28+
```
29+
30+
Run `make lint-fix` to invoke [unify](https://github.com/myint/unify) to deal with your quotes if flake8 complaints
31+
about it.
32+
33+
## Debug messages
34+
35+
Please import the `logger_debug_enabled` variable and wrap your debug messages with a check.
36+
37+
This should be done for all performance critical components.
38+
39+
```python
40+
if logger_debug_enabled:
41+
logger.debug('Message - %s', some_func())
42+
```
43+
44+
# Imports
45+
46+
Please make sure the imports are placed in a good order, or flake8-isort will notify you of the violations.
47+
48+
Run `make lint-fix` to automatically fix the sorting problem.
49+
50+
# Naming
51+
52+
In PEP8 convention, we are required to use snake_case as the accepted style.
53+
54+
However, there are special cases. For example, you are overriding/monkey-patching a method which happens to use the old
55+
style camelCase naming,
56+
then it is acceptable to have the original naming convention to preserve context.
57+
58+
Please mark the line with `# noqa` to avoid linting.

Diff for: engine/models/__init__.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2022 SkyAPM org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# Licensed under the Apache License, Version 2.0 (the "License");
16+
# you may not use this file except in compliance with the License.
17+
# You may obtain a copy of the License at
18+
#
19+
# http://www.apache.org/licenses/LICENSE-2.0
20+
#
21+
# Unless required by applicable law or agreed to in writing, software
22+
# distributed under the License is distributed on an "AS IS" BASIS,
23+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24+
# See the License for the specific language governing permissions and
25+
# limitations under the License.

Diff for: engine/models/metric/base/__init__.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
from .detector import BaseDetector
1+
# Copyright 2022 SkyAPM org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# Licensed under the Apache License, Version 2.0 (the "License");
16+
# you may not use this file except in compliance with the License.
17+
# You may obtain a copy of the License at
18+
#
19+
# http://www.apache.org/licenses/LICENSE-2.0
20+
#
21+
# Unless required by applicable law or agreed to in writing, software
22+
# distributed under the License is distributed on an "AS IS" BASIS,
23+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24+
# See the License for the specific language governing permissions and
25+
# limitations under the License.
226

27+
from .detector import BaseDetector
328

4-
__all__ = ["BaseDetector"]
29+
__all__ = ['BaseDetector']

Diff for: engine/models/metric/base/detector.py

+31-9
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,59 @@
1+
# Copyright 2022 SkyAPM org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# Licensed under the Apache License, Version 2.0 (the "License");
16+
# you may not use this file except in compliance with the License.
17+
# You may obtain a copy of the License at
18+
#
19+
# http://www.apache.org/licenses/LICENSE-2.0
20+
#
21+
# Unless required by applicable law or agreed to in writing, software
22+
# distributed under the License is distributed on an "AS IS" BASIS,
23+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24+
# See the License for the specific language governing permissions and
25+
# limitations under the License.
26+
127
from abc import ABC, abstractmethod
228
from typing import Union
3-
from datetime import datetime
4-
from dateutil.parser import parse
5-
import numpy as np
29+
630

731
class BaseDetector(ABC):
8-
"""Abstract class for Detector, supporting for customize detector."""
32+
"""Abstract class for Detector, supporting for customize detectors."""
933

1034
def __init__(self):
1135
"""Initialization BaseDetector"""
12-
self.data_type = "multivariate"
36+
self.data_type = 'multivariate'
1337
self.index = -1
1438
self.window_len = 100
1539

1640
def _check(self, timestamp: str, X: Union[float, int]) -> bool:
17-
"""Check whether the detector can handle the data."""
41+
"""Check whether the detectors can handle the data."""
1842

1943
assert type(X) in [
2044
float,
2145
int
22-
], "Please input X with float or int type."
46+
], 'Please input X with float or int type.'
2347
assert type(timestamp)
2448

2549
self.index += 1
2650

2751
@abstractmethod
2852
def fit(self, X: float):
29-
3053
return NotImplementedError
3154

3255
@abstractmethod
3356
def score(self, X: float) -> float:
34-
3557
return NotImplementedError
3658

3759
def fit_score(self, timestamp: str, X: Union[float, int]) -> float:

0 commit comments

Comments
 (0)