Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
c14a7a17
N
nightingale
项目概览
DiDi
/
nightingale
11 个月 前同步成功
通知
46
Star
7053
Fork
1161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c14a7a17
编写于
4月 17, 2020
作者:
陈
陈键冬
提交者:
GitHub
4月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Try to fix broken tests (#89)
* Try to fix broken tests * Remove uesless function
上级
2d8ffb43
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
18 addition
and
41 deletion
+18
-41
src/modules/collector/log/reader/reader.go
src/modules/collector/log/reader/reader.go
+1
-1
src/modules/collector/log/reader/reader_util.go
src/modules/collector/log/reader/reader_util.go
+2
-16
src/modules/collector/log/reader/reader_util_test.go
src/modules/collector/log/reader/reader_util_test.go
+9
-17
src/modules/collector/log/worker/control.go
src/modules/collector/log/worker/control.go
+3
-5
src/modules/collector/log/worker/control_test.go
src/modules/collector/log/worker/control_test.go
+2
-1
src/modules/collector/log/worker/worker.go
src/modules/collector/log/worker/worker.go
+1
-1
未找到文件。
src/modules/collector/log/reader/reader.go
浏览文件 @
c14a7a17
...
...
@@ -114,7 +114,7 @@ func (r *Reader) Start() {
}
func
(
r
*
Reader
)
check
()
{
nextpath
:=
Get
Now
Path
(
r
.
FilePath
)
nextpath
:=
Get
Current
Path
(
r
.
FilePath
)
// 文件名发生变化, 一般发生在配置了动态日志场景
if
r
.
CurrentPath
!=
nextpath
{
...
...
src/modules/collector/log/reader/reader_util.go
浏览文件 @
c14a7a17
...
...
@@ -9,15 +9,11 @@ import (
"time"
)
func
GetNowPath
(
path
string
)
string
{
return
getLogPath
(
path
,
true
)
}
func
GetCurrentPath
(
path
string
)
string
{
return
getLogPath
(
path
,
false
)
return
getLogPath
(
path
)
}
func
getLogPath
(
path
string
,
isnext
bool
)
string
{
func
getLogPath
(
path
string
)
string
{
pat
:=
`(\$\{(%[YmdH][^\/]*)+\})`
reg
:=
regexp
.
MustCompile
(
pat
)
return
reg
.
ReplaceAllStringFunc
(
path
,
func
(
s
string
)
string
{
...
...
@@ -29,16 +25,6 @@ func getLogPath(path string, isnext bool) string {
})
name
:=
strings
.
Split
(
strings
.
TrimLeft
(
stringv
,
"%"
),
"%"
)
now
:=
time
.
Now
()
if
isnext
{
switch
name
[
len
(
name
)
-
1
]
{
case
"Y"
,
"m"
,
"d"
:
if
now
.
Hour
()
==
23
{
now
=
time
.
Now
()
//.Add(time.Hour)
}
case
"H"
:
now
=
time
.
Now
()
//.Add(time.Hour)
}
}
for
k
,
v
:=
range
name
{
if
strings
.
Contains
(
v
,
"Y"
)
{
if
strings
.
HasPrefix
(
v
,
"Y"
)
{
...
...
src/modules/collector/log/reader/reader_util_test.go
浏览文件 @
c14a7a17
...
...
@@ -4,27 +4,19 @@ import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var
(
path
=
"/home/${%Y%m}/log/${%Y%m%d}/application.log.${%Y-%m-%d-%H}"
)
func
TestGetcurrentpath
(
t
*
testing
.
T
)
{
path
:=
"/home/${%Y%m}/log/${%Y%m%d}/application.log.${%Y-%m-%d-%H}"
func
TestGetCurrentPath
(
t
*
testing
.
T
)
{
now
:=
time
.
Now
()
dir1
:=
now
.
Format
(
"200601"
)
dir2
:=
now
.
Format
(
"20060102"
)
suffix
:=
now
.
Format
(
"2006-01-02-15"
)
shouldbe
:=
fmt
.
Sprintf
(
"/home/%s/log/%s/application.log.%s"
,
dir1
,
dir2
,
suffix
)
if
GetCurrentPath
(
path
)
!=
shouldbe
{
t
.
Error
(
"getcurrentpath failed"
)
}
}
func
TestGetnextpath
(
t
*
testing
.
T
)
{
path
:=
"/home/${%Y%m}/log/${%Y%m%d}/application.log.${%Y-%m-%d-%H}"
now
:=
time
.
Now
()
.
Add
(
time
.
Hour
)
dir1
:=
now
.
Format
(
"200601"
)
dir2
:=
now
.
Format
(
"20060102"
)
suffix
:=
now
.
Format
(
"2006-01-02-15"
)
shouldbe
:=
fmt
.
Sprintf
(
"/home/%s/log/%s/application.log.%s"
,
dir1
,
dir2
,
suffix
)
if
GetNextPath
(
path
)
!=
shouldbe
{
t
.
Error
(
"getcurrentpath failed"
)
}
expected
:=
fmt
.
Sprintf
(
"/home/%s/log/%s/application.log.%s"
,
dir1
,
dir2
,
suffix
)
assert
.
Equal
(
t
,
expected
,
GetCurrentPath
(
path
))
}
src/modules/collector/log/worker/control.go
浏览文件 @
c14a7a17
...
...
@@ -6,8 +6,6 @@ import (
"github.com/didi/nightingale/src/modules/collector/log/reader"
"github.com/didi/nightingale/src/modules/collector/log/strategy"
"github.com/didi/nightingale/src/modules/collector/stra"
"github.com/toolkits/pkg/logger"
)
...
...
@@ -44,7 +42,7 @@ func UpdateConfigsLoop() {
FilePath
:
st
.
FilePath
,
}
cache
:=
make
(
chan
string
,
WorkerConfig
.
QueueSize
)
if
err
:=
createJob
(
cfg
,
cache
,
st
);
err
!=
nil
{
if
err
:=
createJob
(
cfg
,
cache
);
err
!=
nil
{
logger
.
Errorf
(
"create job fail [id:%d][filePath:%s][err:%v]"
,
cfg
.
Id
,
cfg
.
FilePath
,
err
)
}
}
...
...
@@ -79,7 +77,7 @@ func GetLatestTmsAndDelay(filepath string) (int64, int64, bool) {
}
//添加任务到管理map( managerjob managerconfig) 启动reader和worker
func
createJob
(
config
*
ConfigInfo
,
cache
chan
string
,
st
*
stra
.
Strategy
)
error
{
func
createJob
(
config
*
ConfigInfo
,
cache
chan
string
)
error
{
if
_
,
ok
:=
ManagerJob
[
config
.
FilePath
];
ok
{
if
_
,
ok
:=
ManagerConfig
[
config
.
Id
];
!
ok
{
ManagerConfig
[
config
.
Id
]
=
config
...
...
@@ -97,7 +95,7 @@ func createJob(config *ConfigInfo, cache chan string, st *stra.Strategy) error {
}
//metric.MetricReadAddReaderNum(config.FilePath)
//启动worker
w
:=
NewWorkerGroup
(
config
.
FilePath
,
cache
,
st
)
w
:=
NewWorkerGroup
(
config
.
FilePath
,
cache
)
ManagerJob
[
config
.
FilePath
]
=
&
Job
{
r
:
r
,
w
:
w
,
...
...
src/modules/collector/log/worker/control_test.go
浏览文件 @
c14a7a17
...
...
@@ -2,6 +2,7 @@ package worker
import
(
"fmt"
"log"
"testing"
"time"
)
...
...
@@ -22,6 +23,6 @@ func TestCreatejobAndDeletejob(t *testing.T) {
fmt
.
Println
(
line
)
}
}
else
{
fmt
.
Println
(
"create job failed : %v"
,
err
)
log
.
Printf
(
"create job failed : %v"
,
err
)
}
}
src/modules/collector/log/worker/worker.go
浏览文件 @
c14a7a17
...
...
@@ -67,7 +67,7 @@ func (this *WorkerGroup) SetLatestTmsAndDelay(tms int64, delay int64) {
/*
* filepath和stream依赖外部,其他的都自己创建
*/
func
NewWorkerGroup
(
filePath
string
,
stream
chan
string
,
st
*
stra
.
Strategy
)
*
WorkerGroup
{
func
NewWorkerGroup
(
filePath
string
,
stream
chan
string
)
*
WorkerGroup
{
wokerNum
:=
WorkerConfig
.
WorkerNum
wg
:=
&
WorkerGroup
{
WorkerNum
:
wokerNum
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录