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

rebase git log #578

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
125 changes: 68 additions & 57 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,89 @@ name: CI

on:
push:
branches: master
branches: [ "main", "master" ]
pull_request:
branches: "*"
branches: [ "*" ]

jobs:

lint:
name: Lint check
runs-on: ubuntu-latest
steps:

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Golangci Lint
# https://golangci-lint.run/
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: "--out-format colored-line-number"

build:
name: ${{ matrix.os }} - Go ${{ matrix.go_version }}
name: Build and test - Go ${{ matrix.go_version }}
runs-on: ubuntu-latest
strategy:
# If you want to matrix build , you can append the following list.
# If you want to matrix build , you can append the following list.
matrix:
go_version:
- 1.13
- 1.14
- 1.16
- 1.18
- 1.19
os:
- ubuntu-latest

steps:

- name: Set up Go ${{ matrix.go_version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go_version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Cache build dependence
uses: actions/cache@v2
with:
# Cache
path: ~/go/pkg/mod
# Cache key
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key
restore-keys: ${{ runner.os }}-go-
- name: Set up Go ${{ matrix.go_version }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go_version }}
id: go

- name: Install goimports
run: go get golang.org/x/tools/cmd/goimports
- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Install go ci lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
- name: Cache build dependence
uses: actions/cache@v3
with:
# Cache
path: ~/go/pkg/mod
# Cache key
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key
restore-keys: ${{ runner.os }}-go-

- name: Run Linter
run: golangci-lint run --timeout=10m -v --disable-all --enable=govet --enable=staticcheck --enable=ineffassign --enable=misspell
- name: Test
run: |
go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic
cd ./pkg/datasource/consul
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../etcdv3
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../k8s
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../nacos
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../apollo
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../../adapters/echo
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../gear
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../gin
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../grpc
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../micro
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic

- name: Test
run: |
diff -u <(echo -n) <(gofmt -d -s .)
diff -u <(echo -n) <(goimports -d .)
go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic
cd ./pkg/datasource/consul
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../etcdv3
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../k8s
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../nacos
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../apollo
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../../adapters/echo
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../gear
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../gin
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../grpc
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
cd ../micro
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
- name: Coverage
run: bash <(curl -s https://codecov.io/bash)
- name: Coverage
run: bash <(curl -s https://codecov.io/bash)
29 changes: 29 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Options for analysis running.
run:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
skip-dirs:
- example
skip-files:
- ".*\\.pb\\.go$"
# output configuration options
output:
format: colored-line-number
# Refer to https://golangci-lint.run/usage/linters
linters-settings:
govet:
# Disable analyzers by name.
# Run `go tool vet help` to see all analyzers.
disable:
- stdmethods
linters:
disable-all: true
enable:
- goimports
- gofmt
- misspell
- govet
- ineffassign
- staticcheck
issues:
exclude-use-default: true
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Sentinel: The Sentinel of Your Microservices

![CI](https://github.com/alibaba/sentinel-golang/workflows/CI/badge.svg?branch=master)
[![Build Status](https://travis-ci.org/alibaba/sentinel-golang.svg?branch=master)](https://travis-ci.org/alibaba/sentinel-golang)
[![codecov](https://codecov.io/gh/alibaba/sentinel-golang/branch/master/graph/badge.svg)](https://codecov.io/gh/alibaba/sentinel-golang)
[![GoDoc](https://pkg.go.dev/badge/github.com/alibaba/sentinel-golang)](https://pkg.go.dev/github.com/alibaba/sentinel-golang)
[![Go Report Card](https://goreportcard.com/badge/github.com/alibaba/sentinel-golang)](https://goreportcard.com/report/github.com/alibaba/sentinel-golang)
[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
[![Gitter](https://badges.gitter.im/alibaba/Sentinel.svg)](https://gitter.im/alibaba/Sentinel)
Expand All @@ -17,20 +17,21 @@
## Introduction

As distributed systems become increasingly popular, the reliability between services is becoming more important than ever before.
Sentinel takes "flow" as breakthrough point, and works on multiple fields including **flow control**,
**circuit breaking** and **system adaptive protection**, to guarantee reliability and resiliency of microservices.
Sentinel takes "flow" as breakthrough point, and works on multiple fields including **flow control**, **traffic shaping**, **concurrency limiting**, **circuit breaking** and **system adaptive overload protection**, to guarantee reliability and resiliency of microservices.

![flow-overview](https://raw.githubusercontent.com/sentinel-group/sentinel-website/master/img/sentinel-flow-index-overview-en.jpg)

Sentinel provides the following features:

- **Rich applicable scenarios**: Sentinel has been wildly used in Alibaba, and has covered almost all the core-scenarios in Double-11 (11.11) Shopping Festivals in the past 10 years, such as “Second Kill” which needs to limit burst flow traffic to meet the system capacity, throttling, circuit breaking for unreliable downstream services, distributed rate limiting, etc.
- **Real-time monitoring**: Sentinel also provides real-time monitoring ability. You can see the runtime information of a single machine in real-time, and pump the metrics to outside metric components like Prometheus.
- **Cloud-native ecosystem**: Sentinel Go provides out-of-box integrations with cloud-native components.
- **Cloud-native ecosystem**: Sentinel Go provides [out-of-box integrations with cloud-native components](https://sentinelguard.io/en-us/docs/golang/open-source-framework-integrations.html).

## Documentation

See the [中文文档](https://sentinelguard.io/zh-cn/docs/golang/basic-api-usage.html) for document in Chinese.
[![GoDoc](https://pkg.go.dev/badge/github.com/alibaba/sentinel-golang)](https://pkg.go.dev/github.com/alibaba/sentinel-golang)

See the [中文文档](https://sentinelguard.io/zh-cn/docs/golang/basic-api-usage.html) for the document in Chinese.

See the [Wiki](https://github.com/alibaba/sentinel-golang/wiki) for full documentation, examples, blog posts, and other information.

Expand All @@ -39,11 +40,8 @@ It's also encouraged to add the link of your blog post, tutorial, demo or custom

## Sub-projects

All integration modules and sub-projects are located in [sentinel-group](https://github.com/sentinel-group).

- [Sentinel Go adapters for frameworks](https://github.com/sentinel-group/sentinel-go-adapters)
- [Sentinel Go dynamic data-source modules](https://github.com/sentinel-group/sentinel-go-datasources)
- [Kubernetes CRD data-source for Sentinel Go](https://github.com/sentinel-group/sentinel-go-datasource-k8s-crd)
- [Sentinel Go adapters for frameworks](https://sentinelguard.io/en-us/docs/golang/open-source-framework-integrations.html)
- [Sentinel Go dynamic data-source modules](https://sentinelguard.io/en-us/docs/golang/dynamic-data-source-usage.html)

## Bugs and Feedback

Expand Down
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func WithAttachment(key interface{}, value interface{}) EntryOption {
}
}

// WithAttachment set the resource entry with the given k-v pairs
// WithAttachments set the resource entry with the given k-v pairs
func WithAttachments(data map[interface{}]interface{}) EntryOption {
return func(opts *EntryOptions) {
if opts.attachments == nil {
Expand Down
79 changes: 39 additions & 40 deletions api/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,43 @@
//
// Here is the example code to use Sentinel:
//
// import sentinel "github.com/alibaba/sentinel-golang/api"
//
// err := sentinel.InitDefault()
// if err != nil {
// log.Fatal(err)
// }
//
// //Load sentinel rules
// _, err = flow.LoadRules([]*flow.Rule{
// {
// Resource: "some-test",
// MetricType: flow.QPS,
// Threshold: 10,
// ControlBehavior: flow.Reject,
// },
// })
// if err != nil {
// log.Fatalf("Unexpected error: %+v", err)
// return
// }
// ch := make(chan struct{})
// for i := 0; i < 10; i++ {
// go func() {
// for {
// e, b := sentinel.Entry("some-test", sentinel.WithTrafficType(base.Inbound))
// if b != nil {
// // Blocked. We could get the block reason from the BlockError.
// time.Sleep(time.Duration(rand.Uint64()%10) * time.Millisecond)
// } else {
// // Passed, wrap the logic here.
// fmt.Println(util.CurrentTimeMillis(), "passed")
// time.Sleep(time.Duration(rand.Uint64()%10) * time.Millisecond)
// // Be sure the entry is exited finally.
// e.Exit()
// }
// }
// }()
// }
// <-ch
//
// import sentinel "github.com/alibaba/sentinel-golang/api"
//
// err := sentinel.InitDefault()
// if err != nil {
// log.Fatal(err)
// }
//
// //Load sentinel rules
// _, err = flow.LoadRules([]*flow.Rule{
// {
// Resource: "some-test",
// MetricType: flow.QPS,
// Threshold: 10,
// ControlBehavior: flow.Reject,
// },
// })
// if err != nil {
// log.Fatalf("Unexpected error: %+v", err)
// return
// }
// ch := make(chan struct{})
// for i := 0; i < 10; i++ {
// go func() {
// for {
// e, b := sentinel.Entry("some-test", sentinel.WithTrafficType(base.Inbound))
// if b != nil {
// // Blocked. We could get the block reason from the BlockError.
// time.Sleep(time.Duration(rand.Uint64()%10) * time.Millisecond)
// } else {
// // Passed, wrap the logic here.
// fmt.Println(util.CurrentTimeMillis(), "passed")
// time.Sleep(time.Duration(rand.Uint64()%10) * time.Millisecond)
// // Be sure the entry is exited finally.
// e.Exit()
// }
// }
// }()
// }
// <-ch
package api
7 changes: 4 additions & 3 deletions api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import (
)

// Initialization func initialize the Sentinel's runtime environment, including:
// 1. override global config, from manually config or yaml file or env variable
// 2. override global logger
// 3. initiate core component async task, including: metric log, system statistic...
// 1. override global config, from manually config or yaml file or env variable
// 2. override global logger
// 3. initiate core component async task, including: metric log, system statistic...
//
// InitDefault initializes Sentinel using the configuration from system
// environment and the default value.
func InitDefault() error {
Expand Down
2 changes: 1 addition & 1 deletion core/base/slot_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func NewSlotChain() *SlotChain {
}
}

// Get a EntryContext from EntryContext ctxPool, if ctxPool doesn't have enough EntryContext then new one.
// Get an EntryContext from EntryContext ctxPool, if ctxPool doesn't have enough EntryContext then new one.
func (sc *SlotChain) GetPooledContext() *EntryContext {
ctx := sc.ctxPool.Get().(*EntryContext)
ctx.startTime = util.CurrentTimeMillis()
Expand Down
Loading
Loading