Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
ab8fa0de
Unverified
Commit
ab8fa0de
authored
Jul 26, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
elasticsearch: support reversed index patterns
Now both [index-]pattern and pattern[-index] are supported
parent
7699451d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
9 deletions
+53
-9
pkg/tsdb/elasticsearch/client/index_pattern.go
+27
-8
pkg/tsdb/elasticsearch/client/index_pattern_test.go
+26
-1
No files found.
pkg/tsdb/elasticsearch/client/index_pattern.go
View file @
ab8fa0de
...
@@ -248,13 +248,28 @@ var datePatternReplacements = map[string]string{
...
@@ -248,13 +248,28 @@ var datePatternReplacements = map[string]string{
func
formatDate
(
t
time
.
Time
,
pattern
string
)
string
{
func
formatDate
(
t
time
.
Time
,
pattern
string
)
string
{
var
datePattern
string
var
datePattern
string
parts
:=
strings
.
Split
(
strings
.
TrimLeft
(
pattern
,
"["
),
"]"
)
base
:=
""
base
:=
parts
[
0
]
ltr
:=
false
if
len
(
parts
)
==
2
{
datePattern
=
parts
[
1
]
if
strings
.
HasPrefix
(
pattern
,
"["
)
{
}
else
{
parts
:=
strings
.
Split
(
strings
.
TrimLeft
(
pattern
,
"["
),
"]"
)
datePattern
=
base
base
=
parts
[
0
]
base
=
""
if
len
(
parts
)
==
2
{
datePattern
=
parts
[
1
]
}
else
{
datePattern
=
base
base
=
""
}
ltr
=
true
}
else
if
strings
.
HasSuffix
(
pattern
,
"]"
)
{
parts
:=
strings
.
Split
(
strings
.
TrimRight
(
pattern
,
"]"
),
"["
)
datePattern
=
parts
[
0
]
if
len
(
parts
)
==
2
{
base
=
parts
[
1
]
}
else
{
base
=
""
}
ltr
=
false
}
}
formatted
:=
t
.
Format
(
patternToLayout
(
datePattern
))
formatted
:=
t
.
Format
(
patternToLayout
(
datePattern
))
...
@@ -293,7 +308,11 @@ func formatDate(t time.Time, pattern string) string {
...
@@ -293,7 +308,11 @@ func formatDate(t time.Time, pattern string) string {
formatted
=
strings
.
Replace
(
formatted
,
"<stdHourNoZero>"
,
fmt
.
Sprintf
(
"%d"
,
t
.
Hour
()),
-
1
)
formatted
=
strings
.
Replace
(
formatted
,
"<stdHourNoZero>"
,
fmt
.
Sprintf
(
"%d"
,
t
.
Hour
()),
-
1
)
}
}
return
base
+
formatted
if
ltr
{
return
base
+
formatted
}
return
formatted
+
base
}
}
func
patternToLayout
(
pattern
string
)
string
{
func
patternToLayout
(
pattern
string
)
string
{
...
...
pkg/tsdb/elasticsearch/client/index_pattern_test.go
View file @
ab8fa0de
...
@@ -28,29 +28,54 @@ func TestIndexPattern(t *testing.T) {
...
@@ -28,29 +28,54 @@ func TestIndexPattern(t *testing.T) {
to
:=
fmt
.
Sprintf
(
"%d"
,
time
.
Date
(
2018
,
5
,
15
,
17
,
55
,
0
,
0
,
time
.
UTC
)
.
UnixNano
()
/
int64
(
time
.
Millisecond
))
to
:=
fmt
.
Sprintf
(
"%d"
,
time
.
Date
(
2018
,
5
,
15
,
17
,
55
,
0
,
0
,
time
.
UTC
)
.
UnixNano
()
/
int64
(
time
.
Millisecond
))
indexPatternScenario
(
intervalHourly
,
"[data-]YYYY.MM.DD.HH"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
indexPatternScenario
(
intervalHourly
,
"[data-]YYYY.MM.DD.HH"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
//
So(indices, ShouldHaveLength, 1)
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018.05.15.17"
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018.05.15.17"
)
})
})
indexPatternScenario
(
intervalHourly
,
"YYYY.MM.DD.HH[-data]"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"2018.05.15.17-data"
)
})
indexPatternScenario
(
intervalDaily
,
"[data-]YYYY.MM.DD"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
indexPatternScenario
(
intervalDaily
,
"[data-]YYYY.MM.DD"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018.05.15"
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018.05.15"
)
})
})
indexPatternScenario
(
intervalDaily
,
"YYYY.MM.DD[-data]"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"2018.05.15-data"
)
})
indexPatternScenario
(
intervalWeekly
,
"[data-]GGGG.WW"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
indexPatternScenario
(
intervalWeekly
,
"[data-]GGGG.WW"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018.20"
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018.20"
)
})
})
indexPatternScenario
(
intervalWeekly
,
"GGGG.WW[-data]"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"2018.20-data"
)
})
indexPatternScenario
(
intervalMonthly
,
"[data-]YYYY.MM"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
indexPatternScenario
(
intervalMonthly
,
"[data-]YYYY.MM"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018.05"
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018.05"
)
})
})
indexPatternScenario
(
intervalMonthly
,
"YYYY.MM[-data]"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"2018.05-data"
)
})
indexPatternScenario
(
intervalYearly
,
"[data-]YYYY"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
indexPatternScenario
(
intervalYearly
,
"[data-]YYYY"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018"
)
So
(
indices
[
0
],
ShouldEqual
,
"data-2018"
)
})
})
indexPatternScenario
(
intervalYearly
,
"YYYY[-data]"
,
tsdb
.
NewTimeRange
(
from
,
to
),
func
(
indices
[]
string
)
{
So
(
indices
,
ShouldHaveLength
,
1
)
So
(
indices
[
0
],
ShouldEqual
,
"2018-data"
)
})
})
})
Convey
(
"Hourly interval"
,
t
,
func
()
{
Convey
(
"Hourly interval"
,
t
,
func
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment