-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathrpc.go
730 lines (608 loc) · 17.7 KB
/
rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
// Copyright (c) 2014-2019 Ludovic Fauvet
// Licensed under the MIT license
package rpc
import (
"fmt"
"log"
"net"
"net/url"
"os"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"syscall"
. "github.com/etix/mirrorbits/config"
"github.com/etix/mirrorbits/core"
"github.com/etix/mirrorbits/database"
"github.com/etix/mirrorbits/mirrors"
"github.com/etix/mirrorbits/network"
"github.com/etix/mirrorbits/scan"
"github.com/etix/mirrorbits/utils"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/empty"
"github.com/gomodule/redigo/redis"
"github.com/pkg/errors"
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
"gopkg.in/yaml.v2"
)
var (
// ErrNameAlreadyTaken is returned when the request name is already taken by another mirror
ErrNameAlreadyTaken = errors.New("name already taken")
)
// CLI object handles the server side RPC of the CLI
type CLI struct {
listener net.Listener
server *grpc.Server
sig chan<- os.Signal
redis *database.Redis
cache *mirrors.Cache
}
func (c *CLI) Start() error {
var err error
c.listener, err = net.Listen("tcp", GetConfig().RPCListenAddress)
if err != nil {
return err
}
c.server = grpc.NewServer(
grpc.UnaryInterceptor(UnaryInterceptor),
grpc.StreamInterceptor(StreamInterceptor),
)
RegisterCLIServer(c.server, c)
reflection.Register(c.server)
go func() {
if err := c.server.Serve(c.listener); err != nil {
log.Fatalf("failed to serve rpc: %v", err)
}
}()
return nil
}
func (c *CLI) Close() error {
c.server.Stop()
return c.listener.Close()
}
func (c *CLI) SetSignals(sig chan<- os.Signal) {
c.sig = sig
}
func (c *CLI) SetDatabase(r *database.Redis) {
c.redis = r
}
func (c *CLI) SetCache(cache *mirrors.Cache) {
c.cache = cache
}
func (c *CLI) Ping(context.Context, *empty.Empty) (*empty.Empty, error) {
return &empty.Empty{}, nil
}
func (c *CLI) GetVersion(context.Context, *empty.Empty) (*VersionReply, error) {
return &VersionReply{
Version: core.VERSION,
Build: core.BUILD + core.DEV,
GoVersion: runtime.Version(),
OS: runtime.GOOS,
Arch: runtime.GOARCH,
GoMaxProcs: int32(runtime.GOMAXPROCS(0)),
}, nil
}
func (c *CLI) Upgrade(ctx context.Context, in *empty.Empty) (*empty.Empty, error) {
select {
case c.sig <- syscall.SIGUSR2:
default:
return nil, status.Error(codes.Internal, "signal handler not ready")
}
return &empty.Empty{}, nil
}
func (c *CLI) Reload(ctx context.Context, in *empty.Empty) (*empty.Empty, error) {
select {
case c.sig <- syscall.SIGHUP:
default:
return nil, status.Error(codes.Internal, "signal handler not ready")
}
return &empty.Empty{}, nil
}
func (c *CLI) MatchMirror(ctx context.Context, in *MatchRequest) (*MatchReply, error) {
if c.redis == nil {
return nil, status.Error(codes.Internal, "database not ready")
}
mirrors, err := c.redis.GetListOfMirrors()
if err != nil {
return nil, errors.Wrap(err, "can't fetch the list of mirrors")
}
reply := &MatchReply{}
for id, name := range mirrors {
if strings.Contains(strings.ToLower(name), strings.ToLower(in.Pattern)) {
reply.Mirrors = append(reply.Mirrors, &MirrorID{
ID: int32(id),
Name: name,
})
}
}
return reply, nil
}
func (c *CLI) ChangeStatus(ctx context.Context, in *ChangeStatusRequest) (*empty.Empty, error) {
if in.ID <= 0 {
return nil, status.Error(codes.FailedPrecondition, "invalid mirror id")
}
var err error
switch in.Enabled {
case true:
err = mirrors.EnableMirror(c.redis, int(in.ID))
case false:
err = mirrors.DisableMirror(c.redis, int(in.ID))
}
return &empty.Empty{}, err
}
func (c *CLI) List(ctx context.Context, in *empty.Empty) (*MirrorListReply, error) {
conn, err := c.redis.Connect()
if err != nil {
return nil, err
}
defer conn.Close()
mirrorsIDs, err := c.redis.GetListOfMirrors()
if err != nil {
return nil, errors.Wrap(err, "can't fetch the list of mirrors")
}
conn.Send("MULTI")
for id := range mirrorsIDs {
conn.Send("HGETALL", fmt.Sprintf("MIRROR_%d", id))
}
res, err := redis.Values(conn.Do("EXEC"))
if err != nil {
return nil, errors.Wrap(err, "database error")
}
reply := &MirrorListReply{}
for _, e := range res {
var mirror mirrors.Mirror
res, ok := e.([]interface{})
if !ok {
return nil, errors.New("typecast failed")
}
err = redis.ScanStruct([]interface{}(res), &mirror)
if err != nil {
return nil, errors.Wrap(err, "scan struct failed")
}
m, err := MirrorToRPC(&mirror)
if err != nil {
return nil, err
}
reply.Mirrors = append(reply.Mirrors, m)
}
return reply, nil
}
func (c *CLI) MirrorInfo(ctx context.Context, in *MirrorIDRequest) (*Mirror, error) {
if in.ID <= 0 {
return nil, status.Error(codes.FailedPrecondition, "invalid mirror id")
}
conn, err := c.redis.Connect()
if err != nil {
return nil, err
}
defer conn.Close()
m, err := redis.Values(conn.Do("HGETALL", fmt.Sprintf("MIRROR_%d", in.ID)))
if err != nil {
return nil, err
}
var mi mirrors.Mirror
err = redis.ScanStruct(m, &mi)
if err != nil {
return nil, err
}
rpcm, err := MirrorToRPC(&mi)
if err != nil {
return nil, err
}
return rpcm, nil
}
func (c *CLI) AddMirror(ctx context.Context, in *Mirror) (*AddMirrorReply, error) {
mirror, err := MirrorFromRPC(in)
if err != nil {
return nil, err
}
if mirror.ID != 0 {
return nil, status.Error(codes.FailedPrecondition, "unexpected ID")
}
u, err := url.Parse(mirror.HttpURL)
if err != nil {
return nil, errors.Wrap(err, "can't parse http url")
}
reply := &AddMirrorReply{}
ip, err := network.LookupMirrorIP(u.Host)
if err == network.ErrMultipleAddresses {
reply.Warnings = append(reply.Warnings,
"Warning: the hostname returned more than one address. Assuming they're sharing the same location.")
} else if err != nil {
return nil, errors.Wrap(err, "IP lookup failed")
}
geo := network.NewGeoIP()
if err := geo.LoadGeoIP(); err != nil {
return nil, errors.WithStack(err)
}
geoRec := geo.GetRecord(ip)
if geoRec.IsValid() {
mirror.Latitude = geoRec.Latitude
mirror.Longitude = geoRec.Longitude
mirror.ContinentCode = geoRec.ContinentCode
mirror.CountryCodes = geoRec.CountryCode
mirror.Asnum = geoRec.ASNum
reply.Latitude = geoRec.Latitude
reply.Longitude = geoRec.Longitude
reply.Continent = geoRec.ContinentCode
reply.Country = geoRec.Country
reply.ASN = fmt.Sprintf("%s (%d)", geoRec.ASName, geoRec.ASNum)
} else {
reply.Warnings = append(reply.Warnings,
"Warning: unable to guess the geographic location of this mirror")
}
return reply, c.setMirror(mirror)
}
func (c *CLI) UpdateMirror(ctx context.Context, in *Mirror) (*UpdateMirrorReply, error) {
mirror, err := MirrorFromRPC(in)
if err != nil {
return nil, err
}
if mirror.ID <= 0 {
return nil, status.Error(codes.FailedPrecondition, "invalid mirror id")
}
conn, err := c.redis.Connect()
if err != nil {
return &UpdateMirrorReply{}, err
}
defer conn.Close()
m, err := redis.Values(conn.Do("HGETALL", fmt.Sprintf("MIRROR_%d", mirror.ID)))
if err != nil {
return nil, err
}
var original mirrors.Mirror
err = redis.ScanStruct(m, &original)
if err != nil {
return nil, err
}
diff := createDiff(&original, mirror)
return &UpdateMirrorReply{
Diff: diff,
}, c.setMirror(mirror)
}
func createDiff(mirror1, mirror2 *mirrors.Mirror) (out string) {
yamlo, _ := yaml.Marshal(mirror1)
yamln, _ := yaml.Marshal(mirror2)
splito := strings.Split(string(yamlo), "\n")
splitn := strings.Split(string(yamln), "\n")
for i, l := range splito {
if l != splitn[i] {
out += fmt.Sprintf("- %s\n+ %s\n", l, splitn[i])
}
}
return
}
func (c *CLI) setMirror(mirror *mirrors.Mirror) error {
conn, err := c.redis.Connect()
if err != nil {
return err
}
defer conn.Close()
mirrorsIDs, err := c.redis.GetListOfMirrors()
if err != nil {
return errors.Wrap(err, "can't fetch the list of mirrors")
}
isUpdate := false
for id, name := range mirrorsIDs {
if id == mirror.ID {
isUpdate = true
}
if mirror.ID != id && name == mirror.Name {
return ErrNameAlreadyTaken
}
}
if mirror.ID <= 0 {
// Generate a new ID
mirror.ID, err = redis.Int(conn.Do("INCR", "LAST_MID"))
if err != nil {
return errors.Wrap(err, "failed creating a new id")
}
}
// Reformat contry codes
mirror.CountryCodes = utils.SanitizeLocationCodes(mirror.CountryCodes)
mirror.ExcludedCountryCodes = utils.SanitizeLocationCodes(mirror.ExcludedCountryCodes)
// Reformat continent code
mirror.ContinentCode = utils.SanitizeLocationCodes(mirror.ContinentCode)
// Normalize URLs
if mirror.HttpURL != "" {
mirror.HttpURL = utils.NormalizeURL(mirror.HttpURL)
}
if mirror.RsyncURL != "" {
mirror.RsyncURL = utils.NormalizeURL(mirror.RsyncURL)
}
if mirror.FtpURL != "" {
mirror.FtpURL = utils.NormalizeURL(mirror.FtpURL)
}
// Save the values back into redis
conn.Send("MULTI")
conn.Send("HMSET", fmt.Sprintf("MIRROR_%d", mirror.ID),
"ID", mirror.ID,
"name", mirror.Name,
"http", mirror.HttpURL,
"rsync", mirror.RsyncURL,
"ftp", mirror.FtpURL,
"sponsorName", mirror.SponsorName,
"sponsorURL", mirror.SponsorURL,
"sponsorLogo", mirror.SponsorLogoURL,
"adminName", mirror.AdminName,
"adminEmail", mirror.AdminEmail,
"customData", mirror.CustomData,
"continentOnly", mirror.ContinentOnly,
"countryOnly", mirror.CountryOnly,
"asOnly", mirror.ASOnly,
"score", mirror.Score,
"latitude", mirror.Latitude,
"longitude", mirror.Longitude,
"continentCode", mirror.ContinentCode,
"countryCodes", mirror.CountryCodes,
"excludedCountryCodes", mirror.ExcludedCountryCodes,
"asnum", mirror.Asnum,
"comment", mirror.Comment,
"allowredirects", mirror.AllowRedirects,
"enabled", mirror.Enabled)
// The name of the mirror has been changed.
conn.Send("HSET", "MIRRORS", mirror.ID, mirror.Name)
_, err = conn.Do("EXEC")
if err != nil {
return errors.Wrap(err, "couldn't save the mirror configuration")
}
// Publish update
database.Publish(conn, database.MIRROR_UPDATE, strconv.Itoa(mirror.ID))
if isUpdate {
// This was an update of an existing mirror
mirrors.PushLog(c.redis, mirrors.NewLogEdited(mirror.ID))
} else {
// We just added a new mirror
mirrors.PushLog(c.redis, mirrors.NewLogAdded(mirror.ID))
}
return nil
}
func (c *CLI) RemoveMirror(ctx context.Context, in *MirrorIDRequest) (*empty.Empty, error) {
if in.ID <= 0 {
return nil, status.Error(codes.FailedPrecondition, "invalid mirror id")
}
conn, err := c.redis.Connect()
if err != nil {
return nil, err
}
defer conn.Close()
// First disable the mirror
err = mirrors.DisableMirror(c.redis, int(in.ID))
if err != nil {
return nil, errors.Wrap(err, "unable to disable the mirror")
}
// Get all files supported by the given mirror
files, err := redis.Strings(conn.Do("SMEMBERS", fmt.Sprintf("MIRRORFILES_%d", in.ID)))
if err != nil {
return nil, errors.Wrap(err, "unable to fetch the file list")
}
conn.Send("MULTI")
// Remove each FILEINFO / FILEMIRRORS
for _, file := range files {
conn.Send("DEL", fmt.Sprintf("FILEINFO_%d_%s", in.ID, file))
conn.Send("SREM", fmt.Sprintf("FILEMIRRORS_%s", file), in.ID)
conn.Send("PUBLISH", database.MIRROR_FILE_UPDATE, fmt.Sprintf("%d %s", in.ID, file))
}
// Remove all other keys
conn.Send("DEL",
fmt.Sprintf("MIRROR_%d", in.ID),
fmt.Sprintf("MIRRORFILES_%d", in.ID),
fmt.Sprintf("MIRRORFILESTMP_%d", in.ID),
fmt.Sprintf("HANDLEDFILES_%d", in.ID),
fmt.Sprintf("SCANNING_%d", in.ID),
fmt.Sprintf("MIRRORLOGS_%d", in.ID))
// Remove the last reference
conn.Send("HDEL", "MIRRORS", in.ID)
_, err = conn.Do("EXEC")
if err != nil {
return nil, errors.Wrap(err, "operation failed")
}
// Publish update
database.Publish(conn, database.MIRROR_UPDATE, strconv.Itoa(int(in.ID)))
return &empty.Empty{}, nil
}
func (c *CLI) RefreshRepository(ctx context.Context, in *RefreshRepositoryRequest) (*empty.Empty, error) {
return &empty.Empty{}, scan.ScanSource(c.redis, in.Rehash, nil)
}
func (c *CLI) ScanMirror(ctx context.Context, in *ScanMirrorRequest) (*ScanMirrorReply, error) {
if in.ID <= 0 {
return nil, status.Error(codes.FailedPrecondition, "invalid mirror id")
}
conn, err := c.redis.Connect()
if err != nil {
return nil, err
}
defer conn.Close()
// Check if the local repository has been scanned already
exists, err := redis.Bool(conn.Do("EXISTS", "FILES"))
if err != nil {
return nil, err
}
if !exists {
return nil, status.Error(codes.FailedPrecondition, "local repository not yet indexed. You should run 'refresh' first!")
}
key := fmt.Sprintf("MIRROR_%d", in.ID)
m, err := redis.Values(conn.Do("HGETALL", key))
if err != nil {
return nil, err
}
var mirror mirrors.Mirror
err = redis.ScanStruct(m, &mirror)
if err != nil {
return nil, err
}
var wg sync.WaitGroup
trace := scan.NewTraceHandler(c.redis, make(<-chan struct{}))
wg.Add(1)
go func() {
defer wg.Done()
err := trace.GetLastUpdate(mirror)
if err != nil && err != scan.ErrNoTrace {
if numError, ok := err.(*strconv.NumError); ok {
if numError.Err == strconv.ErrSyntax {
//log.Warningf("[%s] parsing trace file failed: %s is not a valid timestamp", mirror.Name, strconv.Quote(numError.Num))
return
}
} else {
//log.Warningf("[%s] fetching trace file failed: %s", mirror.Name, err)
}
}
}()
err = scan.ErrNoSyncMethod
var res *scan.ScanResult
if in.Protocol == ScanMirrorRequest_ALL {
// Use rsync (if applicable) and fallback to FTP
if mirror.RsyncURL != "" {
res, err = scan.Scan(core.RSYNC, c.redis, c.cache, mirror.RsyncURL, mirror.ID, ctx.Done())
}
if err != nil && mirror.FtpURL != "" {
res, err = scan.Scan(core.FTP, c.redis, c.cache, mirror.FtpURL, mirror.ID, ctx.Done())
}
} else {
// Use the requested protocol
if in.Protocol == ScanMirrorRequest_RSYNC && mirror.RsyncURL != "" {
res, err = scan.Scan(core.RSYNC, c.redis, c.cache, mirror.RsyncURL, mirror.ID, ctx.Done())
} else if in.Protocol == ScanMirrorRequest_FTP && mirror.FtpURL != "" {
res, err = scan.Scan(core.FTP, c.redis, c.cache, mirror.FtpURL, mirror.ID, ctx.Done())
}
}
if err != nil {
return nil, errors.New(fmt.Sprintf("scanning %s failed: %s", mirror.Name, err))
}
reply := &ScanMirrorReply{
FilesIndexed: res.FilesIndexed,
KnownIndexed: res.KnownIndexed,
Removed: res.Removed,
TZOffsetMs: res.TZOffsetMs,
}
// Finally enable the mirror if requested
if err == nil && in.AutoEnable == true {
if err := mirrors.EnableMirror(c.redis, mirror.ID); err != nil {
return nil, errors.Wrap(err, "couldn't enable the mirror")
}
reply.Enabled = true
}
wg.Wait()
return reply, nil
}
func (c *CLI) StatsFile(ctx context.Context, in *StatsFileRequest) (*StatsFileReply, error) {
conn, err := c.redis.Connect()
if err != nil {
return nil, err
}
defer conn.Close()
// Convert the timestamps
start, err := ptypes.Timestamp(in.DateStart)
if err != nil {
return nil, err
}
end, err := ptypes.Timestamp(in.DateEnd)
if err != nil {
return nil, err
}
// Compile the regex pattern
re, err := regexp.Compile(in.Pattern)
if err != nil {
return nil, err
}
// Generate the list of redis key for the period
tkcoverage := utils.TimeKeyCoverage(start, end)
// Prepare the transaction
conn.Send("MULTI")
for _, k := range tkcoverage {
conn.Send("HGETALL", "STATS_FILE_"+k)
}
stats, err := redis.Values(conn.Do("EXEC"))
if err != nil {
return nil, errors.Wrap(err, "can't fetch stats")
}
reply := &StatsFileReply{
Files: make(map[string]int64),
}
for _, res := range stats {
line, ok := res.([]interface{})
if !ok {
return nil, errors.Wrap(err, "typecast failed")
} else {
stats := []interface{}(line)
for i := 0; i < len(stats); i += 2 {
path, _ := redis.String(stats[i], nil)
matched := re.MatchString(path)
if matched {
reqs, _ := redis.Int64(stats[i+1], nil)
reply.Files[path] += reqs
}
}
}
}
return reply, nil
}
func (c *CLI) StatsMirror(ctx context.Context, in *StatsMirrorRequest) (*StatsMirrorReply, error) {
if in.ID <= 0 {
return nil, status.Error(codes.FailedPrecondition, "invalid mirror id")
}
conn, err := c.redis.Connect()
if err != nil {
return nil, err
}
defer conn.Close()
// Convert the timestamps
start, err := ptypes.Timestamp(in.DateStart)
if err != nil {
return nil, err
}
end, err := ptypes.Timestamp(in.DateEnd)
if err != nil {
return nil, err
}
// Generate the list of redis key for the period
tkcoverage := utils.TimeKeyCoverage(start, end)
conn.Send("MULTI")
// Fetch the stats
for _, k := range tkcoverage {
conn.Send("HGET", "STATS_MIRROR_"+k, in.ID)
conn.Send("HGET", "STATS_MIRROR_BYTES_"+k, in.ID)
}
stats, err := redis.Strings(conn.Do("EXEC"))
if err != nil {
return nil, errors.Wrap(err, "can't fetch stats")
}
// Fetch the mirror struct
m, err := redis.Values(conn.Do("HGETALL", fmt.Sprintf("MIRROR_%d", in.ID)))
if err != nil {
return nil, errors.WithMessage(err, "can't fetch mirror")
}
reply := &StatsMirrorReply{}
var mirror mirrors.Mirror
err = redis.ScanStruct(m, &mirror)
if err != nil {
return nil, errors.Wrap(err, "stats error")
}
reply.Mirror, err = MirrorToRPC(&mirror)
if err != nil {
return nil, errors.Wrap(err, "stats error")
}
for i := 0; i < len(stats); i += 2 {
v1, _ := strconv.ParseInt(stats[i], 10, 64)
v2, _ := strconv.ParseInt(stats[i+1], 10, 64)
reply.Requests += v1
reply.Bytes += v2
}
return reply, nil
}
func (c *CLI) GetMirrorLogs(ctx context.Context, in *GetMirrorLogsRequest) (*GetMirrorLogsReply, error) {
if in.ID <= 0 {
return nil, status.Error(codes.FailedPrecondition, "invalid mirror id")
}
lines, err := mirrors.ReadLogs(c.redis, int(in.ID), int(in.MaxResults))
if err != nil {
return nil, errors.Wrap(err, "mirror logs error")
}
return &GetMirrorLogsReply{Line: lines}, nil
}