chore: code format (#72)
* chore: code format * chore: remove fetch-depth * chore: add format and lint * chore: add pr_check * fix: lint with config * chore: this pr only unit test * fix: code format error
This commit is contained in:
parent
fb4dafecb3
commit
8da176bea8
|
@ -0,0 +1,307 @@
|
||||||
|
name: Unit Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
env:
|
||||||
|
GO_VERSION: 1.23.4
|
||||||
|
NODEJS_VERSION: 16.20.2
|
||||||
|
PNAME: console
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
format_check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout current repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: ${{ env.PNAME }}
|
||||||
|
|
||||||
|
- name: Checkout framework repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: infinilabs/framework
|
||||||
|
path: framework
|
||||||
|
|
||||||
|
- name: Checkout framework-vendor
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
|
repository: infinilabs/framework-vendor
|
||||||
|
path: vendor
|
||||||
|
|
||||||
|
- name: Set up nodejs toolchain
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODEJS_VERSION }}
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
node_modules
|
||||||
|
key: ${{ runner.os }}-cnpm-${{ hashFiles('**/package.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cnpm-
|
||||||
|
|
||||||
|
- name: Check nodejs toolchain
|
||||||
|
run: |
|
||||||
|
if ! command -v cnpm >/dev/null 2>&1; then
|
||||||
|
npm install -g rimraf --quiet --no-progress
|
||||||
|
npm install -g cnpm@9.2.0 --quiet --no-progress
|
||||||
|
fi
|
||||||
|
node -v && npm -v && cnpm -v
|
||||||
|
|
||||||
|
- name: Set up go toolchain
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GO_VERSION }}
|
||||||
|
check-latest: false
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Check go toolchain
|
||||||
|
run: go version
|
||||||
|
|
||||||
|
- name: Cache Build Output
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
.public
|
||||||
|
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-
|
||||||
|
${{ runner.os }}-build-
|
||||||
|
|
||||||
|
- name: Code format
|
||||||
|
env:
|
||||||
|
GOFLAGS: -tags=ci
|
||||||
|
run: |
|
||||||
|
echo Home path is $HOME
|
||||||
|
export WORKBASE=$HOME/go/src/infini.sh
|
||||||
|
export WORK=$WORKBASE/console
|
||||||
|
|
||||||
|
# for test workspace
|
||||||
|
mkdir -p $HOME/go/src/
|
||||||
|
ln -s $GITHUB_WORKSPACE $WORKBASE
|
||||||
|
|
||||||
|
# for web build
|
||||||
|
cd $WORK/web
|
||||||
|
cnpm install --quiet --no-progress
|
||||||
|
cnpm run build --quiet
|
||||||
|
|
||||||
|
# check work folder
|
||||||
|
ls -lrt $WORKBASE/
|
||||||
|
ls -alrt $WORK
|
||||||
|
|
||||||
|
# for code format
|
||||||
|
cd $WORK
|
||||||
|
echo Formating code at $PWD ...
|
||||||
|
make format
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "make format failed, please check make output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Check for changes after format
|
||||||
|
id: check-changes
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
export WORKBASE=$HOME/go/src/infini.sh
|
||||||
|
export WORK=$WORKBASE/$PNAME
|
||||||
|
|
||||||
|
# for foramt check
|
||||||
|
cd $WORK
|
||||||
|
if [[ $(git status --porcelain | grep -c " M .*\.go$") -gt 0 ]]; then
|
||||||
|
echo "go format detected formatting changes"
|
||||||
|
echo "changes=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "go format no changes found"
|
||||||
|
echo "changes=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Fail workflow if changes after format
|
||||||
|
if: steps.check-changes.outputs.changes == 'true'
|
||||||
|
run: exit 1
|
||||||
|
|
||||||
|
unit_test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout current repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: ${{ env.PNAME }}
|
||||||
|
|
||||||
|
- name: Checkout framework repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: infinilabs/framework
|
||||||
|
path: framework
|
||||||
|
|
||||||
|
- name: Checkout framework-vendor
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
|
repository: infinilabs/framework-vendor
|
||||||
|
path: vendor
|
||||||
|
|
||||||
|
- name: Set up nodejs toolchain
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODEJS_VERSION }}
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
node_modules
|
||||||
|
key: ${{ runner.os }}-cnpm-${{ hashFiles('**/package.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cnpm-
|
||||||
|
|
||||||
|
- name: Check nodejs toolchain
|
||||||
|
run: |
|
||||||
|
if ! command -v cnpm >/dev/null 2>&1; then
|
||||||
|
npm install -g rimraf --quiet --no-progress
|
||||||
|
npm install -g cnpm@9.2.0 --quiet --no-progress
|
||||||
|
fi
|
||||||
|
node -v && npm -v && cnpm -v
|
||||||
|
|
||||||
|
- name: Set up go toolchain
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GO_VERSION }}
|
||||||
|
check-latest: false
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Check go toolchain
|
||||||
|
run: go version
|
||||||
|
|
||||||
|
- name: Cache Build Output
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
.public
|
||||||
|
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-
|
||||||
|
${{ runner.os }}-build-
|
||||||
|
|
||||||
|
- name: Unit test
|
||||||
|
env:
|
||||||
|
GOFLAGS: -tags=ci
|
||||||
|
run: |
|
||||||
|
echo Home path is $HOME
|
||||||
|
export WORKBASE=$HOME/go/src/infini.sh
|
||||||
|
export WORK=$WORKBASE/$PNAME
|
||||||
|
|
||||||
|
# for test workspace
|
||||||
|
mkdir -p $HOME/go/src/
|
||||||
|
ln -s $GITHUB_WORKSPACE $WORKBASE
|
||||||
|
|
||||||
|
# for web build
|
||||||
|
cd $WORK/web
|
||||||
|
cnpm install --quiet --no-progress
|
||||||
|
cnpm run build --quiet
|
||||||
|
|
||||||
|
# check work folder
|
||||||
|
ls -lrt $WORKBASE/
|
||||||
|
ls -alrt $WORK
|
||||||
|
|
||||||
|
# for unit test
|
||||||
|
cd $WORK
|
||||||
|
echo Testing code at $PWD ...
|
||||||
|
make test
|
||||||
|
|
||||||
|
code_lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout current repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: ${{ env.PNAME }}
|
||||||
|
|
||||||
|
- name: Checkout framework repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: infinilabs/framework
|
||||||
|
path: framework
|
||||||
|
|
||||||
|
- name: Checkout framework-vendor
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
|
repository: infinilabs/framework-vendor
|
||||||
|
path: vendor
|
||||||
|
|
||||||
|
- name: Set up nodejs toolchain
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODEJS_VERSION }}
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
node_modules
|
||||||
|
key: ${{ runner.os }}-cnpm-${{ hashFiles('**/package.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cnpm-
|
||||||
|
|
||||||
|
- name: Check nodejs toolchain
|
||||||
|
run: |
|
||||||
|
if ! command -v cnpm >/dev/null 2>&1; then
|
||||||
|
npm install -g rimraf --quiet --no-progress
|
||||||
|
npm install -g cnpm@9.2.0 --quiet --no-progress
|
||||||
|
fi
|
||||||
|
node -v && npm -v && cnpm -v
|
||||||
|
|
||||||
|
- name: Set up go toolchain
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GO_VERSION }}
|
||||||
|
check-latest: false
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Check go toolchain
|
||||||
|
run: go version
|
||||||
|
|
||||||
|
- name: Cache Build Output
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
.public
|
||||||
|
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-
|
||||||
|
${{ runner.os }}-build-
|
||||||
|
|
||||||
|
- name: Code lint
|
||||||
|
env:
|
||||||
|
GOFLAGS: -tags=ci
|
||||||
|
run: |
|
||||||
|
echo Home path is $HOME
|
||||||
|
export WORKBASE=$HOME/go/src/infini.sh
|
||||||
|
export WORK=$WORKBASE/$PNAME
|
||||||
|
|
||||||
|
# for test workspace
|
||||||
|
mkdir -p $HOME/go/src/
|
||||||
|
ln -s $GITHUB_WORKSPACE $WORKBASE
|
||||||
|
|
||||||
|
# for web build
|
||||||
|
cd $WORK/web
|
||||||
|
cnpm install --quiet --no-progress
|
||||||
|
cnpm run build --quiet
|
||||||
|
|
||||||
|
# check work folder
|
||||||
|
ls -lrt $WORKBASE/
|
||||||
|
ls -alrt $WORK
|
||||||
|
|
||||||
|
# for code lint
|
||||||
|
cd $WORK
|
||||||
|
echo Testing code at $PWD ...
|
||||||
|
# make lint
|
|
@ -1,105 +0,0 @@
|
||||||
name: Unit Test
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches: [ "main" ]
|
|
||||||
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
GO_VERSION: 1.23.4
|
|
||||||
NODEJS_VERSION: 16.20.2
|
|
||||||
steps:
|
|
||||||
- name: Checkout current repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
path: console
|
|
||||||
|
|
||||||
- name: Checkout framework repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
repository: infinilabs/framework
|
|
||||||
path: framework
|
|
||||||
|
|
||||||
- name: Checkout framework-vendor
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: main
|
|
||||||
fetch-depth: 0
|
|
||||||
repository: infinilabs/framework-vendor
|
|
||||||
path: vendor
|
|
||||||
|
|
||||||
- name: Set up nodejs toolchain
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: ${{ env.NODEJS_VERSION }}
|
|
||||||
|
|
||||||
- name: Cache dependencies
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
node_modules
|
|
||||||
key: ${{ runner.os }}-cnpm-${{ hashFiles('**/package.json') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-cnpm-
|
|
||||||
|
|
||||||
- name: Check nodejs toolchain
|
|
||||||
run: |
|
|
||||||
if ! command -v cnpm >/dev/null 2>&1; then
|
|
||||||
npm install -g rimraf --quiet --no-progress
|
|
||||||
npm install -g cnpm@9.2.0 --quiet --no-progress
|
|
||||||
fi
|
|
||||||
node -v && npm -v && cnpm -v
|
|
||||||
|
|
||||||
- name: Set up go toolchain
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: ${{ env.GO_VERSION }}
|
|
||||||
check-latest: false
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: Check go toolchain
|
|
||||||
run: go version
|
|
||||||
|
|
||||||
- name: Cache Build Output
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
.public
|
|
||||||
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ github.sha }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-
|
|
||||||
${{ runner.os }}-build-
|
|
||||||
|
|
||||||
- name: Unit test
|
|
||||||
env:
|
|
||||||
GOFLAGS: -tags=ci
|
|
||||||
run: |
|
|
||||||
echo Home path is $HOME
|
|
||||||
export WORKBASE=$HOME/go/src/infini.sh
|
|
||||||
export WORK=$WORKBASE/console
|
|
||||||
|
|
||||||
# for test workspace
|
|
||||||
mkdir -p $HOME/go/src/
|
|
||||||
ln -s $GITHUB_WORKSPACE $WORKBASE
|
|
||||||
|
|
||||||
# for web build
|
|
||||||
cd $WORK/web
|
|
||||||
cnpm install --quiet --no-progress
|
|
||||||
cnpm run build --quiet
|
|
||||||
|
|
||||||
# check work folder
|
|
||||||
ls -lrt $WORKBASE/
|
|
||||||
ls -alrt $WORK
|
|
||||||
|
|
||||||
# for unit test
|
|
||||||
cd $WORK
|
|
||||||
echo Testing code at $PWD ...
|
|
||||||
make test
|
|
|
@ -32,5 +32,7 @@ appveyor.yml
|
||||||
log/
|
log/
|
||||||
.env
|
.env
|
||||||
generated_*.go
|
generated_*.go
|
||||||
|
config/generated.go
|
||||||
|
config/generat*.go
|
||||||
config/initialization.dsl
|
config/initialization.dsl
|
||||||
config/system_config.yml
|
config/system_config.yml
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
const LastCommitLog = "N/A"
|
|
||||||
const BuildDate = "N/A"
|
|
||||||
|
|
||||||
const EOLDate = "N/A"
|
|
||||||
|
|
||||||
const Version = "0.0.1-SNAPSHOT"
|
|
||||||
|
|
||||||
const BuildNumber = "001"
|
|
|
@ -33,6 +33,7 @@ type Condition struct {
|
||||||
Operator string `json:"operator"`
|
Operator string `json:"operator"`
|
||||||
Items []ConditionItem `json:"items"`
|
Items []ConditionItem `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cond *Condition) GetMinimumPeriodMatch() int {
|
func (cond *Condition) GetMinimumPeriodMatch() int {
|
||||||
var minPeriodMatch = 0
|
var minPeriodMatch = 0
|
||||||
for _, citem := range cond.Items {
|
for _, citem := range cond.Items {
|
||||||
|
|
|
@ -43,7 +43,6 @@ type Channel struct {
|
||||||
Enabled bool `json:"enabled" elastic_mapping:"enabled:{type:boolean}"`
|
Enabled bool `json:"enabled" elastic_mapping:"enabled:{type:boolean}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ChannelEmail = "email"
|
ChannelEmail = "email"
|
||||||
ChannelWebhook = "webhook"
|
ChannelWebhook = "webhook"
|
||||||
|
|
|
@ -41,7 +41,6 @@ type Metric struct {
|
||||||
Expression string `json:"expression,omitempty" elastic_mapping:"expression:{type:keyword,copy_to:search_text}"` //告警表达式,自动生成 eg: avg(cpu) > 80
|
Expression string `json:"expression,omitempty" elastic_mapping:"expression:{type:keyword,copy_to:search_text}"` //告警表达式,自动生成 eg: avg(cpu) > 80
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (m *Metric) GenerateExpression() (string, error) {
|
func (m *Metric) GenerateExpression() (string, error) {
|
||||||
if len(m.Items) == 1 {
|
if len(m.Items) == 1 {
|
||||||
return fmt.Sprintf("%s(%s)", m.Items[0].Statistic, m.Items[0].Field), nil
|
return fmt.Sprintf("%s(%s)", m.Items[0].Statistic, m.Items[0].Field), nil
|
||||||
|
|
|
@ -48,4 +48,3 @@ func (r Resource) Validate() error{
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ func (rule *Rule) GetOrInitExpression() (string, error){
|
||||||
rule.Expression = strings.ReplaceAll(sb.String(), "result", metricExp)
|
rule.Expression = strings.ReplaceAll(sb.String(), "result", metricExp)
|
||||||
return rule.Expression, nil
|
return rule.Expression, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNotificationConfig for adapter old version config
|
// GetNotificationConfig for adapter old version config
|
||||||
func (rule *Rule) GetNotificationConfig() *NotificationConfig {
|
func (rule *Rule) GetNotificationConfig() *NotificationConfig {
|
||||||
if rule.NotificationConfig != nil {
|
if rule.NotificationConfig != nil {
|
||||||
|
@ -139,6 +140,7 @@ type FilterParam struct {
|
||||||
End interface{} `json:"end"`
|
End interface{} `json:"end"`
|
||||||
BucketSize string `json:"bucket_size"`
|
BucketSize string `json:"bucket_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//ctx
|
//ctx
|
||||||
//rule expression, rule_id, resource_id, resource_name, event_id, condition_name, preset_value,[group_tags, check_values],
|
//rule expression, rule_id, resource_id, resource_name, event_id, condition_name, preset_value,[group_tags, check_values],
|
||||||
//check_status ,timestamp,
|
//check_status ,timestamp,
|
|
@ -145,9 +145,6 @@ func TestCreateRule( t *testing.T) {
|
||||||
fmt.Println(exp)
|
fmt.Println(exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func TestTimeRange_Include(t *testing.T) {
|
func TestTimeRange_Include(t *testing.T) {
|
||||||
tr := TimeRange{
|
tr := TimeRange{
|
||||||
Start: "08:00",
|
Start: "08:00",
|
||||||
|
|
|
@ -36,6 +36,3 @@ type Cron struct {
|
||||||
Expression string `json:"expression" elastic_mapping:"expression:{type:text}"`
|
Expression string `json:"expression" elastic_mapping:"expression:{type:text}"`
|
||||||
Timezone string `json:"timezone" elastic_mapping:"timezone:{type:keyword}"`
|
Timezone string `json:"timezone" elastic_mapping:"timezone:{type:keyword}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
package insight
|
package insight
|
||||||
|
|
||||||
|
|
||||||
type SeriesItem struct {
|
type SeriesItem struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Options map[string]interface{} `json:"options"`
|
Options map[string]interface{} `json:"options"`
|
||||||
|
|
|
@ -29,9 +29,10 @@ package insight
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"regexp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Metric struct {
|
type Metric struct {
|
||||||
|
|
|
@ -45,6 +45,7 @@ type Layout struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LayoutType string
|
type LayoutType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LayoutTypeWorkspace LayoutType = "workspace"
|
LayoutTypeWorkspace LayoutType = "workspace"
|
||||||
)
|
)
|
|
@ -31,13 +31,13 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
"infini.sh/framework/modules/configs/common"
|
|
||||||
"infini.sh/framework/core/elastic"
|
"infini.sh/framework/core/elastic"
|
||||||
"infini.sh/framework/core/global"
|
"infini.sh/framework/core/global"
|
||||||
"infini.sh/framework/core/kv"
|
"infini.sh/framework/core/kv"
|
||||||
"infini.sh/framework/core/model"
|
"infini.sh/framework/core/model"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
|
"infini.sh/framework/modules/configs/common"
|
||||||
common2 "infini.sh/framework/modules/elastic/common"
|
common2 "infini.sh/framework/modules/elastic/common"
|
||||||
metadata2 "infini.sh/framework/modules/elastic/metadata"
|
metadata2 "infini.sh/framework/modules/elastic/metadata"
|
||||||
"time"
|
"time"
|
||||||
|
|
|
@ -30,8 +30,8 @@ package common
|
||||||
import (
|
import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
"infini.sh/console/modules/agent/model"
|
"infini.sh/console/modules/agent/model"
|
||||||
"infini.sh/framework/modules/configs/common"
|
|
||||||
"infini.sh/framework/core/env"
|
"infini.sh/framework/core/env"
|
||||||
|
"infini.sh/framework/modules/configs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAgentConfig() *model.AgentConfig {
|
func GetAgentConfig() *model.AgentConfig {
|
||||||
|
|
|
@ -86,9 +86,7 @@ func (h *APIHandler) HandleSearchActivityAction(w http.ResponseWriter, req *http
|
||||||
|
|
||||||
clusterFilter, hasAllPrivilege := h.GetClusterFilter(req, "metadata.labels.cluster_id")
|
clusterFilter, hasAllPrivilege := h.GetClusterFilter(req, "metadata.labels.cluster_id")
|
||||||
if !hasAllPrivilege && clusterFilter == nil {
|
if !hasAllPrivilege && clusterFilter == nil {
|
||||||
h.WriteJSON(w, elastic.SearchResponse{
|
h.WriteJSON(w, elastic.SearchResponse{}, http.StatusOK)
|
||||||
|
|
||||||
}, http.StatusOK)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !hasAllPrivilege && clusterFilter != nil {
|
if !hasAllPrivilege && clusterFilter != nil {
|
||||||
|
@ -97,9 +95,7 @@ func (h *APIHandler) HandleSearchActivityAction(w http.ResponseWriter, req *http
|
||||||
|
|
||||||
hasAllPrivilege, indexPrivilege := h.GetCurrentUserIndex(req)
|
hasAllPrivilege, indexPrivilege := h.GetCurrentUserIndex(req)
|
||||||
if !hasAllPrivilege && len(indexPrivilege) == 0 {
|
if !hasAllPrivilege && len(indexPrivilege) == 0 {
|
||||||
h.WriteJSON(w, elastic.SearchResponse{
|
h.WriteJSON(w, elastic.SearchResponse{}, http.StatusOK)
|
||||||
|
|
||||||
}, http.StatusOK)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !hasAllPrivilege {
|
if !hasAllPrivilege {
|
||||||
|
|
|
@ -166,7 +166,6 @@ func (h *APIHandler) FetchClusterInfo(w http.ResponseWriter, req *http.Request,
|
||||||
Units: "query/s",
|
Units: "query/s",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
clusterID := global.MustLookupString(elastic.GlobalSystemElasticsearchID)
|
clusterID := global.MustLookupString(elastic.GlobalSystemElasticsearchID)
|
||||||
intervalField, err := getDateHistogramIntervalField(clusterID, bucketSizeStr)
|
intervalField, err := getDateHistogramIntervalField(clusterID, bucketSizeStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -633,7 +632,6 @@ func (h *APIHandler) GetClusterNodes(w http.ResponseWriter, req *http.Request, p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if v, ok := nodeID.(string); ok {
|
if v, ok := nodeID.(string); ok {
|
||||||
nodeInfos[v] = util.MapStr{
|
nodeInfos[v] = util.MapStr{
|
||||||
"timestamp": hitM["timestamp"],
|
"timestamp": hitM["timestamp"],
|
||||||
|
|
|
@ -207,10 +207,8 @@ func (h *APIHandler) HandleEseSearchAction(w http.ResponseWriter, req *http.Requ
|
||||||
h.Write(w, searchRes.RawResult.Body)
|
h.Write(w, searchRes.RawResult.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (h *APIHandler) HandleValueSuggestionAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleValueSuggestionAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string]interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
exists, client, err := h.GetClusterClient(targetClusterID)
|
exists, client, err := h.GetClusterClient(targetClusterID)
|
||||||
|
|
||||||
|
@ -340,4 +338,3 @@ func (h *APIHandler) HandleTraceIDSearchAction(w http.ResponseWriter, req *http.
|
||||||
}
|
}
|
||||||
h.WriteJSON(w, indexNames, http.StatusOK)
|
h.WriteJSON(w, indexNames, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,8 +211,7 @@ func (h *APIHandler) getDiscoverHosts(w http.ResponseWriter, req *http.Request,
|
||||||
|
|
||||||
func getHostSummary(agentIDs []string, metricName string, summary map[string]util.MapStr) error {
|
func getHostSummary(agentIDs []string, metricName string, summary map[string]util.MapStr) error {
|
||||||
if summary == nil {
|
if summary == nil {
|
||||||
summary = map[string]util.MapStr{
|
summary = map[string]util.MapStr{}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(agentIDs) == 0 {
|
if len(agentIDs) == 0 {
|
||||||
|
@ -506,8 +505,7 @@ func (h *APIHandler) FetchHostInfo(w http.ResponseWriter, req *http.Request, ps
|
||||||
for key, item := range hostMetrics {
|
for key, item := range hostMetrics {
|
||||||
for _, line := range item.Lines {
|
for _, line := range item.Lines {
|
||||||
if _, ok := networkMetrics[line.Metric.Label]; !ok {
|
if _, ok := networkMetrics[line.Metric.Label]; !ok {
|
||||||
networkMetrics[line.Metric.Label] = util.MapStr{
|
networkMetrics[line.Metric.Label] = util.MapStr{}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
networkMetrics[line.Metric.Label][key] = line.Data
|
networkMetrics[line.Metric.Label][key] = line.Data
|
||||||
}
|
}
|
||||||
|
@ -694,8 +692,8 @@ const (
|
||||||
DiskWriteRateMetricKey = "disk_write_rate"
|
DiskWriteRateMetricKey = "disk_write_rate"
|
||||||
DiskPartitionUsageMetricKey = "disk_partition_usage"
|
DiskPartitionUsageMetricKey = "disk_partition_usage"
|
||||||
NetworkInterfaceOutputRateMetricKey = "network_interface_output_rate"
|
NetworkInterfaceOutputRateMetricKey = "network_interface_output_rate"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *APIHandler) GetSingleHostMetrics(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) GetSingleHostMetrics(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
hostID := ps.MustGetParameter("host_id")
|
hostID := ps.MustGetParameter("host_id")
|
||||||
hostInfo := &host.HostInfo{}
|
hostInfo := &host.HostInfo{}
|
||||||
|
|
|
@ -657,7 +657,6 @@ func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clu
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
aggs := map[string]interface{}{}
|
aggs := map[string]interface{}{}
|
||||||
sumAggs := util.MapStr{}
|
sumAggs := util.MapStr{}
|
||||||
|
|
||||||
|
@ -1050,6 +1049,7 @@ type TopTerm struct {
|
||||||
Value float64
|
Value float64
|
||||||
}
|
}
|
||||||
type TopTermOrder []TopTerm
|
type TopTermOrder []TopTerm
|
||||||
|
|
||||||
func (t TopTermOrder) Len() int {
|
func (t TopTermOrder) Len() int {
|
||||||
return len(t)
|
return len(t)
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,15 +149,13 @@ func (h *APIHandler) SearchIndexMetadata(w http.ResponseWriter, req *http.Reques
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
must := []interface{}{
|
must := []interface{}{}
|
||||||
}
|
|
||||||
if indexFilter, hasIndexPri := h.getAllowedIndexFilter(req); hasIndexPri {
|
if indexFilter, hasIndexPri := h.getAllowedIndexFilter(req); hasIndexPri {
|
||||||
if indexFilter != nil {
|
if indexFilter != nil {
|
||||||
must = append(must, indexFilter)
|
must = append(must, indexFilter)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
h.WriteJSON(w, elastic.SearchResponse{
|
h.WriteJSON(w, elastic.SearchResponse{}, http.StatusOK)
|
||||||
}, http.StatusOK)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
boolQuery := util.MapStr{
|
boolQuery := util.MapStr{
|
||||||
|
@ -550,8 +548,7 @@ func (h *APIHandler) FetchIndexInfo(w http.ResponseWriter, req *http.Request, p
|
||||||
for key, item := range metrics {
|
for key, item := range metrics {
|
||||||
for _, line := range item.Lines {
|
for _, line := range item.Lines {
|
||||||
if _, ok := indexMetrics[line.Metric.Label]; !ok {
|
if _, ok := indexMetrics[line.Metric.Label]; !ok {
|
||||||
indexMetrics[line.Metric.Label] = util.MapStr{
|
indexMetrics[line.Metric.Label] = util.MapStr{}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
indexMetrics[line.Metric.Label][key] = line.Data
|
indexMetrics[line.Metric.Label][key] = line.Data
|
||||||
}
|
}
|
||||||
|
@ -1261,8 +1258,7 @@ func (h APIHandler) ListIndex(w http.ResponseWriter, req *http.Request, ps httpr
|
||||||
if keyword != "" {
|
if keyword != "" {
|
||||||
must = append(must, util.MapStr{
|
must = append(must, util.MapStr{
|
||||||
"wildcard": util.MapStr{
|
"wildcard": util.MapStr{
|
||||||
"metadata.index_name":
|
"metadata.index_name": util.MapStr{"value": fmt.Sprintf("*%s*", keyword)},
|
||||||
util.MapStr{"value": fmt.Sprintf("*%s*", keyword)},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1288,7 +1284,6 @@ func (h APIHandler) ListIndex(w http.ResponseWriter, req *http.Request, ps httpr
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esClient := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
|
esClient := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
|
||||||
indexName := orm.GetIndexName(elastic.IndexConfig{})
|
indexName := orm.GetIndexName(elastic.IndexConfig{})
|
||||||
resp, err := esClient.SearchWithRawQueryDSL(indexName, util.MustToJSONBytes(dsl))
|
resp, err := esClient.SearchWithRawQueryDSL(indexName, util.MustToJSONBytes(dsl))
|
||||||
|
|
|
@ -27,6 +27,13 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
"infini.sh/console/core"
|
"infini.sh/console/core"
|
||||||
v1 "infini.sh/console/modules/elastic/api/v1"
|
v1 "infini.sh/console/modules/elastic/api/v1"
|
||||||
|
@ -39,12 +46,6 @@ import (
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"infini.sh/framework/modules/elastic/common"
|
"infini.sh/framework/modules/elastic/common"
|
||||||
"math"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type APIHandler struct {
|
type APIHandler struct {
|
||||||
|
|
|
@ -56,7 +56,6 @@ func TestConvertBucketItemsToAggQueryParams(t *testing.T) {
|
||||||
bucketItem.Parameters["field"] = "metadata.labels.cluster_id"
|
bucketItem.Parameters["field"] = "metadata.labels.cluster_id"
|
||||||
bucketItem.Parameters["size"] = 2
|
bucketItem.Parameters["size"] = 2
|
||||||
|
|
||||||
|
|
||||||
nestBucket := common.BucketItem{}
|
nestBucket := common.BucketItem{}
|
||||||
nestBucket.Key = "key2"
|
nestBucket.Key = "key2"
|
||||||
nestBucket.Type = common.DateHistogramBucket
|
nestBucket.Type = common.DateHistogramBucket
|
||||||
|
@ -88,7 +87,6 @@ func TestConvertBucketItemsToAggQueryParams(t *testing.T) {
|
||||||
bucketItem.Buckets = []*common.BucketItem{}
|
bucketItem.Buckets = []*common.BucketItem{}
|
||||||
bucketItem.Buckets = append(bucketItem.Buckets, &nestBucket)
|
bucketItem.Buckets = append(bucketItem.Buckets, &nestBucket)
|
||||||
|
|
||||||
|
|
||||||
aggs := ConvertBucketItemsToAggQuery([]*common.BucketItem{&bucketItem}, nil)
|
aggs := ConvertBucketItemsToAggQuery([]*common.BucketItem{&bucketItem}, nil)
|
||||||
fmt.Println(util.MustToJSON(aggs))
|
fmt.Println(util.MustToJSON(aggs))
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,6 @@ func (h *APIHandler) getNodeMetrics(ctx context.Context, clusterID string, bucke
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,19 +143,14 @@ func (h *APIHandler) SearchNodeMetadata(w http.ResponseWriter, req *http.Request
|
||||||
}
|
}
|
||||||
clusterFilter, hasPrivilege := h.GetClusterFilter(req, "metadata.cluster_id")
|
clusterFilter, hasPrivilege := h.GetClusterFilter(req, "metadata.cluster_id")
|
||||||
if !hasPrivilege && clusterFilter == nil {
|
if !hasPrivilege && clusterFilter == nil {
|
||||||
h.WriteJSON(w, elastic.SearchResponse{
|
h.WriteJSON(w, elastic.SearchResponse{}, http.StatusOK)
|
||||||
|
|
||||||
}, http.StatusOK)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
must := []interface{}{
|
must := []interface{}{}
|
||||||
}
|
|
||||||
if !hasPrivilege && clusterFilter != nil {
|
if !hasPrivilege && clusterFilter != nil {
|
||||||
must = append(must, clusterFilter)
|
must = append(must, clusterFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
query := util.MapStr{
|
query := util.MapStr{
|
||||||
"aggs": aggs,
|
"aggs": aggs,
|
||||||
"size": reqBody.Size,
|
"size": reqBody.Size,
|
||||||
|
@ -431,8 +426,7 @@ func (h *APIHandler) FetchNodeInfo(w http.ResponseWriter, req *http.Request, ps
|
||||||
for key, item := range metrics {
|
for key, item := range metrics {
|
||||||
for _, line := range item.Lines {
|
for _, line := range item.Lines {
|
||||||
if _, ok := indexMetrics[line.Metric.Label]; !ok {
|
if _, ok := indexMetrics[line.Metric.Label]; !ok {
|
||||||
indexMetrics[line.Metric.Label] = util.MapStr{
|
indexMetrics[line.Metric.Label] = util.MapStr{}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
indexMetrics[line.Metric.Label][key] = line.Data
|
indexMetrics[line.Metric.Label][key] = line.Data
|
||||||
}
|
}
|
||||||
|
@ -1152,6 +1146,7 @@ type ShardsSummary struct {
|
||||||
PriStoreInBytes int64 `json:"pri_store_in_bytes"`
|
PriStoreInBytes int64 `json:"pri_store_in_bytes"`
|
||||||
Timestamp interface{} `json:"timestamp"`
|
Timestamp interface{} `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) getLatestIndices(req *http.Request, min string, max string, clusterID string, result *orm.Result) ([]interface{}, error) {
|
func (h *APIHandler) getLatestIndices(req *http.Request, min string, max string, clusterID string, result *orm.Result) ([]interface{}, error) {
|
||||||
//filter indices
|
//filter indices
|
||||||
allowedIndices, hasAllPrivilege := h.GetAllowedIndices(req, clusterID)
|
allowedIndices, hasAllPrivilege := h.GetAllowedIndices(req, clusterID)
|
||||||
|
@ -1297,7 +1292,6 @@ func (h *APIHandler) getLatestIndices(req *http.Request, min string, max string,
|
||||||
return indices, nil
|
return indices, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (h *APIHandler) GetNodeShards(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) GetNodeShards(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
clusterID := ps.MustGetParameter("id")
|
clusterID := ps.MustGetParameter("id")
|
||||||
if GetMonitorState(clusterID) == elastic.ModeAgentless {
|
if GetMonitorState(clusterID) == elastic.ModeAgentless {
|
||||||
|
|
|
@ -278,5 +278,3 @@ func rewriteTableNamesOfSqlRequest(req *http.Request, distribution string) (stri
|
||||||
}
|
}
|
||||||
return strings.Join(unescapedTableNames, ","), nil
|
return strings.Join(unescapedTableNames, ","), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *APIHandler) HandleCreateSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleCreateSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string] interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
exists, client, err := h.GetClusterClient(targetClusterID)
|
exists, client, err := h.GetClusterClient(targetClusterID)
|
||||||
|
|
||||||
|
@ -106,8 +105,7 @@ func (h *APIHandler) HandleCreateSearchTemplateAction(w http.ResponseWriter, req
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleUpdateSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleUpdateSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string] interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
exists, client, err := h.GetClusterClient(targetClusterID)
|
exists, client, err := h.GetClusterClient(targetClusterID)
|
||||||
|
|
||||||
|
@ -211,8 +209,7 @@ func (h *APIHandler) HandleUpdateSearchTemplateAction(w http.ResponseWriter, req
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleDeleteSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleDeleteSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string] interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
exists, client, err := h.GetClusterClient(targetClusterID)
|
exists, client, err := h.GetClusterClient(targetClusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -274,8 +271,7 @@ func (h *APIHandler) HandleDeleteSearchTemplateAction(w http.ResponseWriter, req
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleSearchSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleSearchSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string] interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
name = h.GetParameterOrDefault(req, "name", "")
|
name = h.GetParameterOrDefault(req, "name", "")
|
||||||
strFrom = h.GetParameterOrDefault(req, "from", "0")
|
strFrom = h.GetParameterOrDefault(req, "from", "0")
|
||||||
|
@ -325,8 +321,7 @@ func (h *APIHandler) HandleGetSearchTemplateAction(w http.ResponseWriter, req *h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleSearchSearchTemplateHistoryAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleSearchSearchTemplateHistoryAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string] interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
templateID = h.GetParameterOrDefault(req, "template_id", "")
|
templateID = h.GetParameterOrDefault(req, "template_id", "")
|
||||||
strFrom = h.GetParameterOrDefault(req, "from", "0")
|
strFrom = h.GetParameterOrDefault(req, "from", "0")
|
||||||
|
@ -357,8 +352,7 @@ func (h *APIHandler) HandleSearchSearchTemplateHistoryAction(w http.ResponseWrit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleRenderTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleRenderTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string] interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
exists, client, err := h.GetClusterClient(targetClusterID)
|
exists, client, err := h.GetClusterClient(targetClusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -395,8 +389,7 @@ func (h *APIHandler) HandleRenderTemplateAction(w http.ResponseWriter, req *http
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleSearchTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string] interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
exists, client, err := h.GetClusterClient(targetClusterID)
|
exists, client, err := h.GetClusterClient(targetClusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -36,8 +36,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *APIHandler) HandleSettingAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleSettingAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string]interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
|
|
||||||
esClient := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
|
esClient := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
|
||||||
|
@ -63,7 +62,6 @@ func (h *APIHandler) HandleSettingAction(w http.ResponseWriter, req *http.Reques
|
||||||
_, err = esClient.Index(indexName, "", reqParams.ID, reqParams, "wait_for")
|
_, err = esClient.Index(indexName, "", reqParams.ID, reqParams, "wait_for")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
resBody["error"] = err
|
resBody["error"] = err
|
||||||
|
@ -75,8 +73,7 @@ func (h *APIHandler) HandleSettingAction(w http.ResponseWriter, req *http.Reques
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleGetSettingAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleGetSettingAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string]interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
|
|
||||||
esClient := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
|
esClient := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
|
||||||
|
|
|
@ -28,12 +28,12 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
"infini.sh/framework/core/event"
|
"infini.sh/framework/core/event"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/modules/elastic/adapter"
|
"infini.sh/framework/modules/elastic/adapter"
|
||||||
"net/http"
|
"net/http"
|
||||||
log "github.com/cihub/seelog"
|
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *APIHandler) GetShardInfo(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) GetShardInfo(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
|
|
@ -131,7 +131,6 @@ func (h *APIHandler) getThreadPoolMetrics(ctx context.Context, clusterID string,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
should := []util.MapStr{
|
should := []util.MapStr{
|
||||||
|
@ -589,7 +588,6 @@ func (h *APIHandler) getThreadPoolMetrics(ctx context.Context, clusterID string,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Get Thread Pool queue
|
//Get Thread Pool queue
|
||||||
aggs := map[string]interface{}{}
|
aggs := map[string]interface{}{}
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *APIHandler) HandleCrateTraceTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleCrateTraceTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string] interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
exists, client, err := h.GetClusterClient(targetClusterID)
|
exists, client, err := h.GetClusterClient(targetClusterID)
|
||||||
|
|
||||||
|
@ -57,9 +56,7 @@ func (h *APIHandler) HandleCrateTraceTemplateAction(w http.ResponseWriter, req *
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var traceReq = &elastic.TraceTemplate{
|
var traceReq = &elastic.TraceTemplate{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
err = h.DecodeJSON(req, traceReq)
|
err = h.DecodeJSON(req, traceReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -88,8 +85,7 @@ func (h *APIHandler) HandleCrateTraceTemplateAction(w http.ResponseWriter, req *
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleSearchTraceTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleSearchTraceTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string] interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
name = h.GetParameterOrDefault(req, "name", "")
|
name = h.GetParameterOrDefault(req, "name", "")
|
||||||
queryDSL = `{"query":{"bool":{"must":[%s]}}, "size": %d, "from": %d}`
|
queryDSL = `{"query":{"bool":{"must":[%s]}}, "size": %d, "from": %d}`
|
||||||
|
@ -126,8 +122,7 @@ func (h *APIHandler) HandleSearchTraceTemplateAction(w http.ResponseWriter, req
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleSaveTraceTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleSaveTraceTemplateAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string]interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
|
|
||||||
reqParams := elastic.TraceTemplate{}
|
reqParams := elastic.TraceTemplate{}
|
||||||
err := h.DecodeJSON(req, &reqParams)
|
err := h.DecodeJSON(req, &reqParams)
|
||||||
|
|
|
@ -77,7 +77,6 @@ const (
|
||||||
SegmentPointsMetricKey = "segment_points_memory"
|
SegmentPointsMetricKey = "segment_points_memory"
|
||||||
VersionMapMetricKey = "segment_version_map"
|
VersionMapMetricKey = "segment_version_map"
|
||||||
FixedBitSetMetricKey = "segment_fixed_bit_set"
|
FixedBitSetMetricKey = "segment_fixed_bit_set"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clusterID string, bucketSize int, min, max int64, indexName string, top int, metricKey string) (map[string]*common.MetricItem, error) {
|
func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clusterID string, bucketSize int, min, max int64, indexName string, top int, metricKey string) (map[string]*common.MetricItem, error) {
|
||||||
|
@ -682,7 +681,6 @@ func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clu
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
aggs := map[string]interface{}{}
|
aggs := map[string]interface{}{}
|
||||||
|
|
||||||
for _, metricItem := range indexMetricItems {
|
for _, metricItem := range indexMetricItems {
|
||||||
|
@ -954,6 +952,7 @@ type TopTerm struct {
|
||||||
Value float64
|
Value float64
|
||||||
}
|
}
|
||||||
type TopTermOrder []TopTerm
|
type TopTermOrder []TopTerm
|
||||||
|
|
||||||
func (t TopTermOrder) Len() int {
|
func (t TopTermOrder) Len() int {
|
||||||
return len(t)
|
return len(t)
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,8 +246,7 @@ func (h *APIHandler) FetchIndexInfo(w http.ResponseWriter, ctx context.Context,
|
||||||
for key, item := range metrics {
|
for key, item := range metrics {
|
||||||
for _, line := range item.Lines {
|
for _, line := range item.Lines {
|
||||||
if _, ok := indexMetrics[line.Metric.Label]; !ok {
|
if _, ok := indexMetrics[line.Metric.Label]; !ok {
|
||||||
indexMetrics[line.Metric.Label] = util.MapStr{
|
indexMetrics[line.Metric.Label] = util.MapStr{}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
indexMetrics[line.Metric.Label][key] = line.Data
|
indexMetrics[line.Metric.Label][key] = line.Data
|
||||||
}
|
}
|
||||||
|
@ -683,7 +682,6 @@ func (h *APIHandler) GetIndexHealthMetric(ctx context.Context, id, indexName str
|
||||||
return metricItem, nil
|
return metricItem, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (h *APIHandler) GetIndexStatusOfRecentDay(clusterID, indexName string) (map[string][]interface{}, error) {
|
func (h *APIHandler) GetIndexStatusOfRecentDay(clusterID, indexName string) (map[string][]interface{}, error) {
|
||||||
q := orm.Query{
|
q := orm.Query{
|
||||||
WildcardIndex: true,
|
WildcardIndex: true,
|
||||||
|
@ -959,8 +957,7 @@ func (h APIHandler) ListIndex(w http.ResponseWriter, req *http.Request, ps httpr
|
||||||
if keyword != "" {
|
if keyword != "" {
|
||||||
must = append(must, util.MapStr{
|
must = append(must, util.MapStr{
|
||||||
"wildcard": util.MapStr{
|
"wildcard": util.MapStr{
|
||||||
"metadata.index_name":
|
"metadata.index_name": util.MapStr{"value": fmt.Sprintf("*%s*", keyword)},
|
||||||
util.MapStr{"value": fmt.Sprintf("*%s*", keyword)},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -986,7 +983,6 @@ func (h APIHandler) ListIndex(w http.ResponseWriter, req *http.Request, ps httpr
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esClient := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
|
esClient := elastic.GetClient(global.MustLookupString(elastic.GlobalSystemElasticsearchID))
|
||||||
indexName := orm.GetIndexName(elastic.IndexConfig{})
|
indexName := orm.GetIndexName(elastic.IndexConfig{})
|
||||||
resp, err := esClient.SearchWithRawQueryDSL(indexName, util.MustToJSONBytes(dsl))
|
resp, err := esClient.SearchWithRawQueryDSL(indexName, util.MustToJSONBytes(dsl))
|
||||||
|
|
|
@ -796,6 +796,7 @@ const (
|
||||||
ShardCountMetricKey = "shard_count"
|
ShardCountMetricKey = "shard_count"
|
||||||
CircuitBreakerMetricKey = "circuit_breaker"
|
CircuitBreakerMetricKey = "circuit_breaker"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *APIHandler) GetClusterMetrics(ctx context.Context, id string, bucketSize int, min, max int64, metricKey string) (map[string]*common.MetricItem, error) {
|
func (h *APIHandler) GetClusterMetrics(ctx context.Context, id string, bucketSize int, min, max int64, metricKey string) (map[string]*common.MetricItem, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -915,12 +916,14 @@ func (h *APIHandler) getClusterMetricsByKey(ctx context.Context, id string, buck
|
||||||
}
|
}
|
||||||
return h.getSingleMetrics(ctx, clusterMetricItems, query, bucketSize)
|
return h.getSingleMetrics(ctx, clusterMetricItems, query, bucketSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
IndexThroughputMetricKey = "index_throughput"
|
IndexThroughputMetricKey = "index_throughput"
|
||||||
SearchThroughputMetricKey = "search_throughput"
|
SearchThroughputMetricKey = "search_throughput"
|
||||||
IndexLatencyMetricKey = "index_latency"
|
IndexLatencyMetricKey = "index_latency"
|
||||||
SearchLatencyMetricKey = "search_latency"
|
SearchLatencyMetricKey = "search_latency"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *APIHandler) GetClusterIndexMetrics(ctx context.Context, id string, bucketSize int, min, max int64, metricKey string) (map[string]*common.MetricItem, error) {
|
func (h *APIHandler) GetClusterIndexMetrics(ctx context.Context, id string, bucketSize int, min, max int64, metricKey string) (map[string]*common.MetricItem, error) {
|
||||||
bucketSizeStr := fmt.Sprintf("%vs", bucketSize)
|
bucketSizeStr := fmt.Sprintf("%vs", bucketSize)
|
||||||
metricItems := []*common.MetricItem{}
|
metricItems := []*common.MetricItem{}
|
||||||
|
|
|
@ -233,6 +233,7 @@ const (
|
||||||
MetricTypeNodeStats = "node_stats"
|
MetricTypeNodeStats = "node_stats"
|
||||||
MetricTypeIndexStats = "index_stats"
|
MetricTypeIndexStats = "index_stats"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetMetricMinBucketSize returns twice the metrics collection interval based on the cluster ID and metric type
|
// GetMetricMinBucketSize returns twice the metrics collection interval based on the cluster ID and metric type
|
||||||
func GetMetricMinBucketSize(clusterID, metricType string) (int, error) {
|
func GetMetricMinBucketSize(clusterID, metricType string) (int, error) {
|
||||||
meta := elastic.GetMetadata(clusterID)
|
meta := elastic.GetMetadata(clusterID)
|
||||||
|
|
|
@ -143,19 +143,14 @@ func (h *APIHandler) SearchNodeMetadata(w http.ResponseWriter, req *http.Request
|
||||||
}
|
}
|
||||||
clusterFilter, hasPrivilege := h.GetClusterFilter(req, "metadata.cluster_id")
|
clusterFilter, hasPrivilege := h.GetClusterFilter(req, "metadata.cluster_id")
|
||||||
if !hasPrivilege && clusterFilter == nil {
|
if !hasPrivilege && clusterFilter == nil {
|
||||||
h.WriteJSON(w, elastic.SearchResponse{
|
h.WriteJSON(w, elastic.SearchResponse{}, http.StatusOK)
|
||||||
|
|
||||||
}, http.StatusOK)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
must := []interface{}{
|
must := []interface{}{}
|
||||||
}
|
|
||||||
if !hasPrivilege && clusterFilter != nil {
|
if !hasPrivilege && clusterFilter != nil {
|
||||||
must = append(must, clusterFilter)
|
must = append(must, clusterFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
query := util.MapStr{
|
query := util.MapStr{
|
||||||
"aggs": aggs,
|
"aggs": aggs,
|
||||||
"size": reqBody.Size,
|
"size": reqBody.Size,
|
||||||
|
@ -426,8 +421,7 @@ func (h *APIHandler) FetchNodeInfo(w http.ResponseWriter, req *http.Request, ps
|
||||||
for key, item := range metrics {
|
for key, item := range metrics {
|
||||||
for _, line := range item.Lines {
|
for _, line := range item.Lines {
|
||||||
if _, ok := indexMetrics[line.Metric.Label]; !ok {
|
if _, ok := indexMetrics[line.Metric.Label]; !ok {
|
||||||
indexMetrics[line.Metric.Label] = util.MapStr{
|
indexMetrics[line.Metric.Label] = util.MapStr{}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
indexMetrics[line.Metric.Label][key] = line.Data
|
indexMetrics[line.Metric.Label][key] = line.Data
|
||||||
}
|
}
|
||||||
|
@ -1102,7 +1096,6 @@ func (h *APIHandler) getLatestIndices(req *http.Request, min string, max string,
|
||||||
return indices, nil
|
return indices, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (h *APIHandler) GetNodeShards(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) GetNodeShards(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
clusterID := ps.MustGetParameter("id")
|
clusterID := ps.MustGetParameter("id")
|
||||||
nodeID := ps.MustGetParameter("node_id")
|
nodeID := ps.MustGetParameter("node_id")
|
||||||
|
|
|
@ -28,9 +28,9 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/crewjam/saml"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"github.com/crewjam/saml"
|
|
||||||
|
|
||||||
"github.com/crewjam/saml/samlsp"
|
"github.com/crewjam/saml/samlsp"
|
||||||
)
|
)
|
||||||
|
|
|
@ -114,7 +114,6 @@ func (h *AlertAPI) ignoreAlertMessage(w http.ResponseWriter, req *http.Request,
|
||||||
_ = kv.DeleteKey(alerting2.KVLastMessageState, []byte(msg.RuleID))
|
_ = kv.DeleteKey(alerting2.KVLastMessageState, []byte(msg.RuleID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
h.WriteJSON(w, util.MapStr{
|
h.WriteJSON(w, util.MapStr{
|
||||||
"ids": messageIDs,
|
"ids": messageIDs,
|
||||||
"result": "updated",
|
"result": "updated",
|
||||||
|
@ -249,7 +248,6 @@ func (h *AlertAPI) getAlertMessageStats(w http.ResponseWriter, req *http.Request
|
||||||
}, http.StatusOK)
|
}, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (h *AlertAPI) searchAlertMessage(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *AlertAPI) searchAlertMessage(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -38,8 +38,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *APIHandler) HandleAddCommonCommandAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleAddCommonCommandAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string]interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
|
|
||||||
reqParams := elastic.CommonCommand{}
|
reqParams := elastic.CommonCommand{}
|
||||||
err := h.DecodeJSON(req, &reqParams)
|
err := h.DecodeJSON(req, &reqParams)
|
||||||
|
@ -85,8 +84,7 @@ func (h *APIHandler) HandleAddCommonCommandAction(w http.ResponseWriter, req *ht
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleSaveCommonCommandAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleSaveCommonCommandAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string]interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
|
|
||||||
reqParams := elastic.CommonCommand{}
|
reqParams := elastic.CommonCommand{}
|
||||||
err := h.DecodeJSON(req, &reqParams)
|
err := h.DecodeJSON(req, &reqParams)
|
||||||
|
@ -130,8 +128,7 @@ func (h *APIHandler) HandleSaveCommonCommandAction(w http.ResponseWriter, req *h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) HandleQueryCommonCommandAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) HandleQueryCommonCommandAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
resBody := map[string]interface{}{
|
resBody := map[string]interface{}{}
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
keyword = h.GetParameterOrDefault(req, "keyword", "")
|
keyword = h.GetParameterOrDefault(req, "keyword", "")
|
||||||
|
|
|
@ -28,13 +28,13 @@
|
||||||
package insight
|
package insight
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
insight2 "infini.sh/console/model/insight"
|
insight2 "infini.sh/console/model/insight"
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *InsightAPI) createDashboard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *InsightAPI) createDashboard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
|
|
@ -34,8 +34,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
|
||||||
"infini.sh/console/model/insight"
|
"infini.sh/console/model/insight"
|
||||||
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,13 +29,13 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
"infini.sh/framework/modules/configs/common"
|
|
||||||
"infini.sh/framework/modules/configs/config"
|
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
config3 "infini.sh/framework/core/config"
|
config3 "infini.sh/framework/core/config"
|
||||||
"infini.sh/framework/core/global"
|
"infini.sh/framework/core/global"
|
||||||
"infini.sh/framework/core/model"
|
"infini.sh/framework/core/model"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
|
"infini.sh/framework/modules/configs/common"
|
||||||
|
"infini.sh/framework/modules/configs/config"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
|
@ -37,13 +37,13 @@ import (
|
||||||
|
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
"infini.sh/console/core/security/enum"
|
"infini.sh/console/core/security/enum"
|
||||||
"infini.sh/framework/modules/configs/common"
|
|
||||||
"infini.sh/framework/core/api"
|
"infini.sh/framework/core/api"
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
elastic2 "infini.sh/framework/core/elastic"
|
elastic2 "infini.sh/framework/core/elastic"
|
||||||
"infini.sh/framework/core/model"
|
"infini.sh/framework/core/model"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
|
"infini.sh/framework/modules/configs/common"
|
||||||
"infini.sh/framework/modules/elastic"
|
"infini.sh/framework/modules/elastic"
|
||||||
common2 "infini.sh/framework/modules/elastic/common"
|
common2 "infini.sh/framework/modules/elastic/common"
|
||||||
)
|
)
|
||||||
|
|
|
@ -32,11 +32,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
"infini.sh/console/core"
|
"infini.sh/console/core"
|
||||||
"infini.sh/framework/modules/configs/common"
|
|
||||||
"infini.sh/framework/core/api"
|
"infini.sh/framework/core/api"
|
||||||
"infini.sh/framework/core/errors"
|
"infini.sh/framework/core/errors"
|
||||||
"infini.sh/framework/core/global"
|
"infini.sh/framework/core/global"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
|
"infini.sh/framework/modules/configs/common"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
|
@ -67,4 +67,3 @@ func (act *WebhookAction) Execute()([]byte, error){
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
return ioutil.ReadAll(res.Body)
|
return ioutil.ReadAll(res.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ const (
|
||||||
KVLastMessageState = "alert_last_message_state"
|
KVLastMessageState = "alert_last_message_state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ParamRuleID = "rule_id" //规则 UUID
|
ParamRuleID = "rule_id" //规则 UUID
|
||||||
ParamResourceID = "resource_id" // 资源 UUID
|
ParamResourceID = "resource_id" // 资源 UUID
|
||||||
|
@ -50,6 +49,7 @@ const (
|
||||||
ParamGroupValues = "group_values"
|
ParamGroupValues = "group_values"
|
||||||
ParamIssueTimestamp = "issue_timestamp"
|
ParamIssueTimestamp = "issue_timestamp"
|
||||||
ParamRelationValues = "relation_values"
|
ParamRelationValues = "relation_values"
|
||||||
|
|
||||||
// rule expression, rule_id, resource_id, resource_name, event_id, condition_name, preset_value,[group_tags, check_values],
|
// rule expression, rule_id, resource_id, resource_name, event_id, condition_name, preset_value,[group_tags, check_values],
|
||||||
// check_status ,timestamp,
|
// check_status ,timestamp,
|
||||||
)
|
)
|
|
@ -34,10 +34,10 @@ import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
"infini.sh/console/model"
|
"infini.sh/console/model"
|
||||||
"infini.sh/console/model/alerting"
|
"infini.sh/console/model/alerting"
|
||||||
|
"infini.sh/console/model/insight"
|
||||||
alerting2 "infini.sh/console/service/alerting"
|
alerting2 "infini.sh/console/service/alerting"
|
||||||
"infini.sh/console/service/alerting/common"
|
"infini.sh/console/service/alerting/common"
|
||||||
"infini.sh/framework/core/elastic"
|
"infini.sh/framework/core/elastic"
|
||||||
"infini.sh/console/model/insight"
|
|
||||||
"infini.sh/framework/core/kv"
|
"infini.sh/framework/core/kv"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
|
@ -50,8 +50,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Engine struct {
|
type Engine struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateQuery generate a final elasticsearch query dsl object
|
// GenerateQuery generate a final elasticsearch query dsl object
|
||||||
// when RawFilter of rule is not empty, priority use it, otherwise to covert from Filter of rule (todo)
|
// when RawFilter of rule is not empty, priority use it, otherwise to covert from Filter of rule (todo)
|
||||||
// auto generate time filter query and then attach to final query
|
// auto generate time filter query and then attach to final query
|
||||||
|
@ -150,6 +150,7 @@ func (engine *Engine) GenerateQuery(rule *alerting.Rule, filterParam *alerting.F
|
||||||
"aggs": rootAggs,
|
"aggs": rootAggs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// generateAgg convert statistic of metric item to elasticsearch aggregation
|
// generateAgg convert statistic of metric item to elasticsearch aggregation
|
||||||
func (engine *Engine) generateAgg(metricItem *insight.MetricItem) map[string]interface{} {
|
func (engine *Engine) generateAgg(metricItem *insight.MetricItem) map[string]interface{} {
|
||||||
var (
|
var (
|
||||||
|
@ -540,6 +541,7 @@ func (engine *Engine) GetTargetMetricData(rule *alerting.Rule, isFilterNaN bool,
|
||||||
}
|
}
|
||||||
return targetMetricData, queryResult, nil
|
return targetMetricData, queryResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckCondition check whether rule conditions triggered or not
|
// CheckCondition check whether rule conditions triggered or not
|
||||||
// if triggered returns an ConditionResult
|
// if triggered returns an ConditionResult
|
||||||
// sort conditions by priority desc before check , and then if condition is true, then continue check another group
|
// sort conditions by priority desc before check , and then if condition is true, then continue check another group
|
||||||
|
@ -1103,8 +1105,6 @@ func performChannels(channels []alerting.Channel, ctx map[string]interface{}, ra
|
||||||
return actionResults, errCount
|
return actionResults, errCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (engine *Engine) GenerateTask(rule alerting.Rule) func(ctx context.Context) {
|
func (engine *Engine) GenerateTask(rule alerting.Rule) func(ctx context.Context) {
|
||||||
return func(ctx context.Context) {
|
return func(ctx context.Context) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -1280,7 +1280,6 @@ func saveAlertMessage(message *alerting.AlertMessage) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func readTimeFromKV(bucketKey string, key []byte) (time.Time, error) {
|
func readTimeFromKV(bucketKey string, key []byte) (time.Time, error) {
|
||||||
timeBytes, err := kv.GetValue(bucketKey, key)
|
timeBytes, err := kv.GetValue(bucketKey, key)
|
||||||
zeroTime := time.Time{}
|
zeroTime := time.Time{}
|
||||||
|
|
|
@ -47,6 +47,7 @@ var (
|
||||||
alertEngines = map[string]Engine{}
|
alertEngines = map[string]Engine{}
|
||||||
alertEnginesMutex = sync.RWMutex{}
|
alertEnginesMutex = sync.RWMutex{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegistEngine(typ string, engine Engine) {
|
func RegistEngine(typ string, engine Engine) {
|
||||||
alertEnginesMutex.Lock()
|
alertEnginesMutex.Lock()
|
||||||
defer alertEnginesMutex.Unlock()
|
defer alertEnginesMutex.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue