Skip to content

How To Use

Eric Zhao edited this page Jul 2, 2019 · 2 revisions

Initialization

void InitSentinel() {
  // The Logger should be initialized at first.
  Sentinel::Log::Logger::InitDefaultLogger();

  // Initialize the HTTP command server.
  Sentinel::Transport::HttpCommandCenterInitTarget command_center_init;
  command_center_init.Initialize();
  // Initialize the metric log task.
  Sentinel::Log::MetricLogTask metric_log_task;
  metric_log_task.Initialize();
}

Define Resources

#include "sentinel-core/public/sph_u.h"

void SentinelEntry() {
  auto r = Sentinel::SphU::Entry(resource_name);
  // ------ response time begin ------

  // Your logic here (should avoid exception!)

  service->DoSomething();

  if (!r->IsBlocked()) {
    // ------ response time end ------
    r.Exit();
  } else {
    // indicates that the request was blocked here
  }
}

Load Rules

Load rules via RuleManager API

#include "sentinel-core/flow/flow_rule_manager.h"

void LoadRules() {
  Sentinel::Flow::FlowRule rule1{"my_open_api_abc"};
  rule1.set_count(8);
  rule1.set_metric_type(Sentinel::Flow::FlowMetricType::kThreadCount);
  Sentinel::Flow::FlowRule rule2{"my_another_service:foo()"};
  rule2.set_count(20);
  Sentinel::Flow::FlowRuleManager::GetInstance().LoadRules({rule1, rule2});
}

Load rules via the dynamic data source

SomeDataSource<std::vector<Sentinel::Flow::FlowRule>> ds(args...);
ds.Init();
Sentinel::Flow::FlowRuleManager::GetInstance().RegisterToProperty(ds.GetProperty());
Clone this wiki locally