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

Method Logs

log-driver/loki/loki.go:179–222  ·  view source on GitHub ↗
(clusterId string, conditions map[string]string, start time.Time, end time.Time, limit int64, offset int64)

Source from the content-addressed store, hash-verified

177}
178
179func (d *Driver) Logs(clusterId string, conditions map[string]string, start time.Time, end time.Time, limit int64, offset int64) ([]*log_driver.LogItem, int64, error) {
180 if start.After(end) {
181 return nil, 0, fmt.Errorf("start time is greater than end time")
182 }
183 if len(conditions) < 1 {
184 return nil, 0, fmt.Errorf("conditions is empty")
185 }
186 if offset < 1 {
187 offset = 1
188 }
189 if limit < 1 {
190 limit = 15
191 }
192 count, err := d.logCount(clusterId, conditions, start, end)
193 if err != nil {
194 return nil, 0, err
195 }
196 if count == 0 {
197 return nil, 0, nil
198 }
199 if count < (offset-1)*limit {
200 return nil, 0, fmt.Errorf("offset is greater than count")
201 }
202 cs := make([]string, 0, len(conditions))
203 for k, v := range conditions {
204 if strings.HasPrefix(k, "#") {
205 cs = append(cs, v)
206 continue
207 }
208 cs = append(cs, fmt.Sprintf("%s=~\"%s\"", k, v))
209 }
210 queries := url.Values{}
211 queries.Set("query", fmt.Sprintf("{cluster=\"%s\"} | json | %s", clusterId, strings.Join(cs, " | ")))
212 queries.Set("limit", strconv.FormatInt(limit, 10))
213 queries.Set("direction", "backward")
214 queries.Set("start", strconv.FormatInt(start.UnixNano(), 10))
215 log.Debug("query is ", queries.Get("query"))
216 logs, err := d.recuseLogs(queries, end, offset)
217 if err != nil {
218 return nil, 0, err
219 }
220
221 return logs, count, nil
222}
223
224func ToLogItem(detail *LogDetail, msec int64) *log_driver.LogItem {
225 return &log_driver.LogItem{

Callers 1

TestLokiFunction · 0.95

Calls 4

logCountMethod · 0.95
recuseLogsMethod · 0.95
SetMethod · 0.65
GetMethod · 0.65

Tested by 1

TestLokiFunction · 0.76