-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: logs list API, logic update for better perf (#5912)
* feat: logsV4 initial refactoring * feat: filter_query builder with tests added * feat: all functions of v4 refactored * fix: tests fixed * feat: logs list API, logic update for better perf * fix: update select for table panel * fix: tests updated with better examples of limit and group by * fix: resource filter support in live tail * feat: cleanup and use flag * feat: restrict new list api to single query * fix: move getTsRanges to utils
- Loading branch information
1 parent
381a4de
commit 90b5f88
Showing
4 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package utils | ||
|
||
const HOUR_NANO = int64(3600000000000) | ||
|
||
type LogsListTsRange struct { | ||
Start int64 | ||
End int64 | ||
} | ||
|
||
func GetLogsListTsRanges(start, end int64) []LogsListTsRange { | ||
startNano := GetEpochNanoSecs(start) | ||
endNano := GetEpochNanoSecs(end) | ||
result := []LogsListTsRange{} | ||
|
||
if endNano-startNano > HOUR_NANO { | ||
bucket := HOUR_NANO | ||
tStartNano := endNano - bucket | ||
|
||
complete := false | ||
for { | ||
result = append(result, LogsListTsRange{Start: tStartNano, End: endNano}) | ||
if complete { | ||
break | ||
} | ||
|
||
bucket = bucket * 2 | ||
endNano = tStartNano | ||
tStartNano = tStartNano - bucket | ||
|
||
// break condition | ||
if tStartNano <= startNano { | ||
complete = true | ||
tStartNano = startNano | ||
} | ||
} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package utils | ||
|
||
import "testing" | ||
|
||
func TestLogsListTsRange(t *testing.T) { | ||
startEndData := []struct { | ||
name string | ||
start int64 | ||
end int64 | ||
res []LogsListTsRange | ||
}{ | ||
{ | ||
name: "testing for less then one hour", | ||
start: 1722262800000000000, // July 29, 2024 7:50:00 PM | ||
end: 1722263800000000000, // July 29, 2024 8:06:40 PM | ||
res: []LogsListTsRange{}, | ||
}, | ||
{ | ||
name: "testing for more than one hour", | ||
start: 1722255800000000000, // July 29, 2024 5:53:20 PM | ||
end: 1722262800000000000, // July 29, 2024 8:06:40 PM | ||
res: []LogsListTsRange{ | ||
{1722259200000000000, 1722262800000000000}, // July 29, 2024 6:50:00 PM - July 29, 2024 7:50:00 PM | ||
{1722255800000000000, 1722259200000000000}, // July 29, 2024 5:53:20 PM - July 29, 2024 6:50:00 PM | ||
}, | ||
}, | ||
{ | ||
name: "testing for 1 day", | ||
start: 1722171576000000000, | ||
end: 1722262800000000000, | ||
res: []LogsListTsRange{ | ||
{1722259200000000000, 1722262800000000000}, // July 29, 2024 6:50:00 PM - July 29, 2024 7:50:00 PM | ||
{1722252000000000000, 1722259200000000000}, // July 29, 2024 4:50:00 PM - July 29, 2024 6:50:00 PM | ||
{1722237600000000000, 1722252000000000000}, // July 29, 2024 12:50:00 PM - July 29, 2024 4:50:00 PM | ||
{1722208800000000000, 1722237600000000000}, // July 29, 2024 4:50:00 AM - July 29, 2024 12:50:00 PM | ||
{1722171576000000000, 1722208800000000000}, // July 28, 2024 6:29:36 PM - July 29, 2024 4:50:00 AM | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range startEndData { | ||
res := GetLogsListTsRanges(test.start, test.end) | ||
for i, v := range res { | ||
if test.res[i].Start != v.Start || test.res[i].End != v.End { | ||
t.Errorf("expected range was %v - %v, got %v - %v", v.Start, v.End, test.res[i].Start, test.res[i].End) | ||
} | ||
} | ||
} | ||
} |