MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / recuseLogs

Method recuseLogs

log-driver/loki/loki.go:247–280  ·  view source on GitHub ↗
(queries url.Values, end time.Time, offset int64)

Source from the content-addressed store, hash-verified

245}
246
247func (d *Driver) recuseLogs(queries url.Values, end time.Time, offset int64) ([]*log_driver.LogItem, error) {
248 queries.Set("end", strconv.FormatInt(end.UnixNano(), 10))
249 list, err := send[LogInfo](http.MethodGet, fmt.Sprintf("%s/loki/api/v1/query_range", d.url), d.headers, queries, "")
250 if err != nil {
251 return nil, err
252 }
253 if len(list) < 1 {
254 return nil, nil
255 }
256 if offset > 1 {
257 // 获取list最后一个元素的时间戳
258 last := list[len(list)-1].Stream
259 if last == nil {
260 return nil, fmt.Errorf("last log is empty")
261 }
262 msec, err := strconv.ParseInt(last.Msec, 10, 64)
263 if err != nil {
264 return nil, fmt.Errorf("parse last log time error: %v", err)
265 }
266 return d.recuseLogs(queries, time.UnixMilli(msec), offset-1)
267 }
268 logs := make([]*log_driver.LogItem, 0, len(list))
269 for _, l := range list {
270 if l.Stream == nil {
271 continue
272 }
273 msec, _ := strconv.ParseInt(l.Stream.Msec, 10, 64)
274 logs = append(logs, ToLogItem(l.Stream, msec))
275 }
276 sort.Slice(logs, func(i, j int) bool {
277 return logs[i].RecordTime.After(logs[j].RecordTime)
278 })
279 return logs, nil
280}
281
282func parseToInt64(v interface{}) int64 {
283 switch t := v.(type) {

Callers 2

LogRecordsMethod · 0.95
LogsMethod · 0.95

Calls 2

ToLogItemFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected