Skip to content

Commit

Permalink
add status log (#152)
Browse files Browse the repository at this point in the history
* add status log

* don't benchmark on pull_request

* feat: semantic release
  • Loading branch information
GopherJ authored May 13, 2020
1 parent d7c9fe6 commit 223f369
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Always validate the PR title AND all the commits
titleAndCommits: true
1 change: 0 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Benchmark
on:
pull_request:
push:
branches:
- master
Expand Down
52 changes: 15 additions & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,23 @@
name: Auto Release

name: Release
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10

branches:
- master
jobs:
release:
name: Auto Release by Tags
name: Release
runs-on: ubuntu-18.04

steps:
- name: Checkout Repository
uses: actions/checkout@master

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
- name: Checkout
uses: actions/checkout@v1
- name: Setup Node.js
uses: actions/setup-node@v1
with:
profile: minimal
toolchain: stable
default: true

- name: Cargo Login
uses: actions-rs/cargo@v1
with:
command: login
args: -- ${{ secrets.CARGO_TOKEN }}

- name: Cargo Publish
uses: actions-rs/cargo@v1
with:
command: publish

- name: GitHub Release
id: create_release
uses: actions/create-release@v1
node-version: 12
- name: Install dependencies
run: npm ci
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
run: cargo login $CARGO_TOKEN && npx semantic-release
16 changes: 16 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"debug": true,
"release": {
"branches": [
"master"
]
},
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github",
["@semantic-release/exec", {
"publishCmd" : "cargo publish"
}]
]
}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "casbin"
version = "0.8.4"
version = "0.8.5"
authors = ["Joey <joey.xf@gmail.com>", "Cheng JIANG <jiang.cheng@vip.163.com>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Add this package to `Cargo.toml` of your project. (Check https://crates.io/crate

```toml
[dependencies]
casbin = { version = "0.8.4", default-features = false, features = ["runtime-async-std", "logging"] }
casbin = { version = "0.8.5", default-features = false, features = ["runtime-async-std", "logging"] }
async-std = { version = "1.5.0", features = ["attributes"] }
env_logger = "0.7.1"
```
Expand Down
2 changes: 1 addition & 1 deletion src/cached_enforcer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl CoreApi for CachedEnforcer {
.into_iter()
.filter_map(|y| all_rules.get_index(y))
.collect();
self.enforcer.get_logger().print_explain_log(rules);
self.enforcer.get_logger().print_expl_log(rules);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/effector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait Effector: Send + Sync {
}

pub trait EffectorStream: Send + Sync {
fn current(&self) -> bool;
fn next(&self) -> bool;
fn expl(&self) -> Option<Vec<usize>>;
fn push_effect(&mut self, eft: EffectKind) -> bool;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Effector for DefaultEffector {

impl EffectorStream for DefaultEffectStream {
#[inline]
fn current(&self) -> bool {
fn next(&self) -> bool {
assert!(self.done);
self.res
}
Expand Down
9 changes: 7 additions & 2 deletions src/enforcer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Enforcer {
};
eft_stream.push_effect(eft);
}
Ok((eft_stream.current(), eft_stream.expl()))
Ok((eft_stream.next(), eft_stream.expl()))
}
}

Expand Down Expand Up @@ -417,7 +417,7 @@ impl CoreApi for Enforcer {
.into_iter()
.filter_map(|y| all_rules.get_index(y))
.collect();
self.logger.print_explain_log(rules);
self.logger.print_expl_log(rules);
}
}
}
Expand Down Expand Up @@ -496,6 +496,11 @@ impl CoreApi for Enforcer {
#[inline]
fn enable_enforce(&mut self, enabled: bool) {
self.enabled = enabled;

#[cfg(feature = "logging")]
{
self.logger.print_status_log(enabled);
}
}

#[cfg(feature = "logging")]
Expand Down
16 changes: 14 additions & 2 deletions src/logger/default_logger.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{emitter::EventData, logger::Logger};

use log::{error, info};
use log::{error, info, warn};

#[derive(Default)]
pub struct DefaultLogger {
Expand Down Expand Up @@ -52,11 +52,23 @@ impl Logger for DefaultLogger {
info!("{}", d);
}

fn print_explain_log(&self, rules: Vec<&Vec<String>>) {
fn print_expl_log(&self, rules: Vec<&Vec<String>>) {
if !self.is_enabled() {
return;
}

info!("Explain: {:?}", rules);
}

fn print_status_log(&self, enabled: bool) {
if !self.is_enabled() {
return;
}

if enabled {
info!("Casbin has been enabled!");
} else {
warn!("Casbin has been disabled!");
}
}
}
5 changes: 3 additions & 2 deletions src/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub trait Logger: Send + Sync {
fn enable_log(&mut self, enabled: bool);
fn is_enabled(&self) -> bool;
fn print_enforce_log(&self, rvals: Vec<String>, authorized: bool, cached: bool);
fn print_mgmt_log(&self, event_data: &EventData);
fn print_explain_log(&self, rules: Vec<&Vec<String>>);
fn print_mgmt_log(&self, d: &EventData);
fn print_expl_log(&self, rules: Vec<&Vec<String>>);
fn print_status_log(&self, enabled: bool);
}

1 comment on commit 223f369

@GopherJ
Copy link
Member Author

Choose a reason for hiding this comment

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

Rust Benchmark

Benchmark suite Current: 223f369 Previous: d7c9fe6 Ratio
b_benchmark_abac_model 7168 ns/iter (± 1626) 7152 ns/iter (± 901) 1.00
b_benchmark_basic_model 7646 ns/iter (± 705) 7857 ns/iter (± 1274) 0.97
b_benchmark_cached_abac_model 448 ns/iter (± 66) 406 ns/iter (± 97) 1.10
b_benchmark_cached_key_match 436 ns/iter (± 51) 419 ns/iter (± 71) 1.04
b_benchmark_cached_priority_model 392 ns/iter (± 52) 411 ns/iter (± 69) 0.95
b_benchmark_cached_rbac_model 397 ns/iter (± 36) 419 ns/iter (± 74) 0.95
b_benchmark_cached_rbac_model_large 393 ns/iter (± 35) 443 ns/iter (± 34) 0.89
b_benchmark_cached_rbac_model_medium 397 ns/iter (± 42) 407 ns/iter (± 40) 0.98
b_benchmark_cached_rbac_model_small 411 ns/iter (± 150) 396 ns/iter (± 37) 1.04
b_benchmark_cached_rbac_model_with_domains 457 ns/iter (± 36) 479 ns/iter (± 40) 0.95
b_benchmark_cached_rbac_with_deny 411 ns/iter (± 41) 420 ns/iter (± 111) 0.98
b_benchmark_cached_rbac_with_resource_roles 396 ns/iter (± 36) 418 ns/iter (± 31) 0.95
b_benchmark_key_match 25779 ns/iter (± 1907) 27912 ns/iter (± 3940) 0.92
b_benchmark_priority_model 8864 ns/iter (± 1070) 9368 ns/iter (± 635) 0.95
b_benchmark_raw 8 ns/iter (± 0) 8 ns/iter (± 0) 1
b_benchmark_rbac_model 21017 ns/iter (± 3469) 23476 ns/iter (± 2083) 0.90
b_benchmark_rbac_model_large 63645550 ns/iter (± 4332732) 64638188 ns/iter (± 4500067) 0.98
b_benchmark_rbac_model_medium 6061021 ns/iter (± 785967) 6181854 ns/iter (± 372296) 0.98
b_benchmark_rbac_model_small 639544 ns/iter (± 59625) 603780 ns/iter (± 56609) 1.06
b_benchmark_rbac_model_with_domains 12818 ns/iter (± 846) 12531 ns/iter (± 1808) 1.02
b_benchmark_rbac_with_deny 36820 ns/iter (± 2593) 38855 ns/iter (± 4372) 0.95
b_benchmark_rbac_with_resource_roles 10217 ns/iter (± 1057) 10557 ns/iter (± 963) 0.97
b_benmark_cached_basic_model 411 ns/iter (± 35) 407 ns/iter (± 47) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.