Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add parameter verification to the visit counter API #3546

Merged
merged 7 commits into from Mar 27, 2023

Conversation

guqing
Copy link
Member

@guqing guqing commented Mar 21, 2023

What type of PR is this?

/kind improvement
/area core
/milestone 2.4.x

What this PR does / why we need it:

对访问量统计的 API 增加数据合法性校验
点赞同理

see #3530 for more details

how to test it?

  1. 访问文章和页面可以统计访问量
  2. 使用访问以下 API 添加模拟使用错误数据不会在 Counter 模型添加记录
curl 'http://localhost:8090/apis/api.halo.run/v1alpha1/trackers/counter' -u 'your-username:your-password'  \
--header 'Content-Type: application/json' \
--data '{
    "group": "fake.halo.run",
    "plural": "posts",
    "name": "fake-name",
    "hostname": "localhost",
    "screen": "1920x1080",
    "language": "zh-CN",
    "url": "/archives/hello-halo",
    "referrer": "http://localhost:8090/"
}'

期望出现日志:

2023-03-21T12:37:08.391+08:00 DEBUG 7036 --- [task-4] r.h.app.metrics.VisitedEventReconciler   : Skip visit event for: GroupPluralName[group=fake.halo.run, plural=posts, name=fake-name]

并且

curl 'http://localhost:8090/apis/metrics.halo.run/v1alpha1/counters' -u 'your-username:your-password'

不会出现上述错误数据的记录

Which issue(s) this PR fixes:

Fixes #3530

Does this PR introduce a user-facing change?

对访问量统计的 API 增加数据合法性校验

@f2c-ci-robot f2c-ci-robot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Mar 21, 2023
@f2c-ci-robot f2c-ci-robot bot added this to the 2.4.x milestone Mar 21, 2023
@f2c-ci-robot f2c-ci-robot bot added the kind/improvement Categorizes issue or PR as related to a improvement. label Mar 21, 2023
@f2c-ci-robot f2c-ci-robot bot added the area/core Issues or PRs related to the Halo Core label Mar 21, 2023
@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Merging #3546 (897bb69) into main (5b3b473) will decrease coverage by 0.16%.
The diff coverage is 4.54%.

@@             Coverage Diff              @@
##               main    #3546      +/-   ##
============================================
- Coverage     59.77%   59.61%   -0.16%     
  Complexity     2189     2189              
============================================
  Files           337      337              
  Lines         11273    11305      +32     
  Branches        837      844       +7     
============================================
+ Hits           6738     6740       +2     
- Misses         4129     4159      +30     
  Partials        406      406              
Impacted Files Coverage Δ
...a/run/halo/app/metrics/VisitedEventReconciler.java 25.33% <3.84%> (-5.18%) ⬇️
...ava/run/halo/app/metrics/VotedEventReconciler.java 28.57% <5.55%> (-8.93%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@JohnNiang
Copy link
Member

需要先解决一下以下冲突:

Conflicting files
src/main/java/run/halo/app/metrics/VisitedEventReconciler.java
src/main/java/run/halo/app/metrics/VotedEventReconciler.java

@f2c-ci-robot f2c-ci-robot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 23, 2023
@f2c-ci-robot f2c-ci-robot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 24, 2023
@guqing
Copy link
Member Author

guqing commented Mar 24, 2023

/ping @halo-dev/sig-halo

@LIlGG
Copy link
Member

LIlGG commented Mar 27, 2023

image

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2023
@f2c-ci-robot f2c-ci-robot bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2023
Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2023
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Mar 27, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JohnNiang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 27, 2023
@f2c-ci-robot f2c-ci-robot bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2023
Copy link
Member

@ruibaby ruibaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2023
@f2c-ci-robot f2c-ci-robot bot merged commit fb2bc42 into halo-dev:main Mar 27, 2023
5 checks passed
@guqing guqing deleted the refactor/3530 branch March 27, 2023 08:04
@ruibaby ruibaby modified the milestones: 2.4.x, 2.4.0 Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/core Issues or PRs related to the Halo Core kind/improvement Categorizes issue or PR as related to a improvement. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

访问量统计的API需要对名称进行校验
4 participants