Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
9c5eab48
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9c5eab48
编写于
6月 25, 2020
作者:
M
Ming Deng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add build info for prometheus
上级
1813d414
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
216 addition
and
0 deletion
+216
-0
build_info.go
build_info.go
+27
-0
metric/prometheus.go
metric/prometheus.go
+25
-0
scripts/gobuild.sh
scripts/gobuild.sh
+112
-0
scripts/report_build_info.sh
scripts/report_build_info.sh
+52
-0
未找到文件。
build_info.go
0 → 100644
浏览文件 @
9c5eab48
// Copyright 2020 astaxie
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
beego
var
(
BuildVersion
string
BuildGitRevision
string
BuildStatus
string
BuildTag
string
BuildTime
string
GoVersion
string
GitBranch
string
)
metric/prometheus.go
浏览文件 @
9c5eab48
...
...
@@ -18,6 +18,7 @@ import (
"net/http"
"reflect"
"strconv"
"strings"
"time"
"github.com/prometheus/client_golang/prometheus"
...
...
@@ -40,6 +41,8 @@ func PrometheusMiddleWare(next http.Handler) http.Handler {
prometheus
.
MustRegister
(
summaryVec
)
registerBuildInfo
()
return
http
.
HandlerFunc
(
func
(
writer
http
.
ResponseWriter
,
q
*
http
.
Request
)
{
start
:=
time
.
Now
()
next
.
ServeHTTP
(
writer
,
q
)
...
...
@@ -48,6 +51,28 @@ func PrometheusMiddleWare(next http.Handler) http.Handler {
})
}
func
registerBuildInfo
()
{
buildInfo
:=
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Name
:
"beego"
,
Subsystem
:
"build_info"
,
Help
:
"The building information"
,
ConstLabels
:
map
[
string
]
string
{
"appname"
:
beego
.
BConfig
.
AppName
,
"build_version"
:
beego
.
BuildVersion
,
"build_revision"
:
beego
.
BuildGitRevision
,
"build_status"
:
beego
.
BuildStatus
,
"build_tag"
:
beego
.
BuildTag
,
"build_time"
:
strings
.
Replace
(
beego
.
BuildTime
,
"--"
,
" "
,
1
),
"go_version"
:
beego
.
GoVersion
,
"git_branch"
:
beego
.
GitBranch
,
"start_time"
:
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
},
},
[]
string
{})
prometheus
.
MustRegister
(
buildInfo
)
buildInfo
.
WithLabelValues
()
.
Set
(
1
)
}
func
report
(
dur
time
.
Duration
,
writer
http
.
ResponseWriter
,
q
*
http
.
Request
,
vec
*
prometheus
.
SummaryVec
)
{
ctrl
:=
beego
.
BeeApp
.
Handlers
ctx
:=
ctrl
.
GetContext
()
...
...
scripts/gobuild.sh
0 → 100755
浏览文件 @
9c5eab48
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".
# Copyright Istio Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script builds and version stamps the output
# adatp to beego
VERBOSE
=
${
VERBOSE
:-
"0"
}
V
=
""
if
[[
"
${
VERBOSE
}
"
==
"1"
]]
;
then
V
=
"-x"
set
-x
fi
SCRIPTPATH
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
OUT
=
${
1
:?
"output path"
}
shift
set
-e
BUILD_GOOS
=
${
GOOS
:-
linux
}
BUILD_GOARCH
=
${
GOARCH
:-
amd64
}
GOBINARY
=
${
GOBINARY
:-
go
}
GOPKG
=
"
$GOPATH
/pkg"
BUILDINFO
=
${
BUILDINFO
:-
""
}
STATIC
=
${
STATIC
:-
1
}
LDFLAGS
=
${
LDFLAGS
:-
-extldflags -static
}
GOBUILDFLAGS
=
${
GOBUILDFLAGS
:-
""
}
# Split GOBUILDFLAGS by spaces into an array called GOBUILDFLAGS_ARRAY.
IFS
=
' '
read
-r
-a
GOBUILDFLAGS_ARRAY
<<<
"
$GOBUILDFLAGS
"
GCFLAGS
=
${
GCFLAGS
:-}
export
CGO_ENABLED
=
0
if
[[
"
${
STATIC
}
"
!=
"1"
]]
;
then
LDFLAGS
=
""
fi
# gather buildinfo if not already provided
# For a release build BUILDINFO should be produced
# at the beginning of the build and used throughout
if
[[
-z
${
BUILDINFO
}
]]
;
then
BUILDINFO
=
$(
mktemp
)
"
${
SCRIPTPATH
}
/report_build_info.sh"
>
"
${
BUILDINFO
}
"
fi
# BUILD LD_EXTRAFLAGS
LD_EXTRAFLAGS
=
""
while
read
-r
line
;
do
LD_EXTRAFLAGS
=
"
${
LD_EXTRAFLAGS
}
-X
${
line
}
"
done
<
"
${
BUILDINFO
}
"
# verify go version before build
# NB. this was copied verbatim from Kubernetes hack
minimum_go_version
=
go1.13
# supported patterns: go1.x, go1.x.x (x should be a number)
IFS
=
" "
read
-ra
go_version
<<<
"
$(
${
GOBINARY
}
version
)
"
if
[[
"
${
minimum_go_version
}
"
!=
$(
echo
-e
"
${
minimum_go_version
}
\n
${
go_version
[2]
}
"
|
sort
-s
-t
.
-k
1,1
-k
2,2n
-k
3,3n |
head
-n1
)
&&
"
${
go_version
[2]
}
"
!=
"devel"
]]
;
then
echo
"Warning: Detected that you are using an older version of the Go compiler. Beego requires
${
minimum_go_version
}
or greater."
fi
CURRENT_BRANCH
=
$(
git branch |
grep
'*'
)
CURRENT_BRANCH
=
${
CURRENT_BRANCH
:2
}
BUILD_TIME
=
$(
date
+%Y-%m-%d--%T
)
LD_EXTRAFLAGS
=
"
${
LD_EXTRAFLAGS
}
-X github.com/astaxie/beego.GoVersion=
${
go_version
[2]
:2
}
"
LD_EXTRAFLAGS
=
"
${
LD_EXTRAFLAGS
}
-X github.com/astaxie/beego.GitBranch=
${
CURRENT_BRANCH
}
"
LD_EXTRAFLAGS
=
"
${
LD_EXTRAFLAGS
}
-X github.com/astaxie/beego.BuildTime=
$BUILD_TIME
"
OPTIMIZATION_FLAGS
=
"-trimpath"
if
[
"
${
DEBUG
}
"
==
"1"
]
;
then
OPTIMIZATION_FLAGS
=
""
fi
echo
"BUILD_GOARCH:
$BUILD_GOARCH
"
echo
"GOPKG:
$GOPKG
"
echo
"LD_EXTRAFLAGS:
$LD_EXTRAFLAGS
"
echo
"GO_VERSION:
${
go_version
[2]
}
"
echo
"BRANCH:
$CURRENT_BRANCH
"
echo
"BUILD_TIME:
$BUILD_TIME
"
time
GOOS
=
${
BUILD_GOOS
}
GOARCH
=
${
BUILD_GOARCH
}
${
GOBINARY
}
build
\
${
V
}
"
${
GOBUILDFLAGS_ARRAY
[@]
}
"
${
GCFLAGS
:+-gcflags
"
${
GCFLAGS
}
"
}
\
-o
"
${
OUT
}
"
\
${
OPTIMIZATION_FLAGS
}
\
-pkgdir
=
"
${
GOPKG
}
/
${
BUILD_GOOS
}
_
${
BUILD_GOARCH
}
"
\
-ldflags
"
${
LDFLAGS
}
${
LD_EXTRAFLAGS
}
"
"
${
@
}
"
\ No newline at end of file
scripts/report_build_info.sh
0 → 100755
浏览文件 @
9c5eab48
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".
# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# adapt to beego
if
BUILD_GIT_REVISION
=
$(
git rev-parse HEAD 2> /dev/null
)
;
then
if
[[
-n
"
$(
git status
--porcelain
2>/dev/null
)
"
]]
;
then
BUILD_GIT_REVISION
=
${
BUILD_GIT_REVISION
}
"-dirty"
fi
else
BUILD_GIT_REVISION
=
unknown
fi
# Check for local changes
if
git diff-index
--quiet
HEAD
--
;
then
tree_status
=
"Clean"
else
tree_status
=
"Modified"
fi
# security wanted VERSION='unknown'
VERSION
=
"
${
BUILD_GIT_REVISION
}
"
if
[[
-n
${
BEEGO_VERSION
}
]]
;
then
VERSION
=
"
${
BEEGO_VERSION
}
"
fi
GIT_DESCRIBE_TAG
=
$(
git describe
--tags
)
echo
"github.com/astaxie/beego.BuildVersion=
${
VERSION
}
"
echo
"github.com/astaxie/beego.BuildGitRevision=
${
BUILD_GIT_REVISION
}
"
echo
"github.com/astaxie/beego.BuildStatus=
${
tree_status
}
"
echo
"github.com/astaxie/beego.BuildTag=
${
GIT_DESCRIBE_TAG
}
"
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录