Skip to content

Commit

Permalink
Merge pull request #2 from ego-component/feat/add-logs
Browse files Browse the repository at this point in the history
feat/add-logs
  • Loading branch information
sevennt authored Sep 2, 2023
2 parents b57be18 + 6d259cd commit 48ef6b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Load(key string) *Container {
c.logger.Panic("parse config error", elog.FieldErr(err), elog.FieldKey(key))
return c
}
c.logger.Debug("config info", elog.String("name", c.name), elog.Any("config", c.config))
c.logger = c.logger.With(elog.FieldComponentName(key))
c.name = key
return c
Expand Down
6 changes: 6 additions & 0 deletions registry/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,20 @@ func (reg *Component) ListServices(ctx context.Context, t eregistry.Target) (ser
// WatchServices watch service change event, then return address list
func (reg *Component) WatchServices(ctx context.Context, t eregistry.Target) (chan eregistry.Endpoints, error) {
appName, port, err := getAppnameAndPort(t.Endpoint)
elog.Debug("WatchServices app info", elog.String("app", appName), elog.String("port", port))
if err != nil {
return nil, err
}

app, err := reg.client.NewWatcherApp(ctx, appName, reg.config.Kind)
if err != nil {
reg.logger.Error("NewWatcherApp fail", elog.FieldErr(err))
return nil, err
}

svcs, err := reg.ListServices(ctx, t)
if err != nil {
reg.logger.Error("ListServices fail", elog.FieldErr(err))
return nil, err
}
var al = &eregistry.Endpoints{
Expand All @@ -138,18 +141,21 @@ func (reg *Component) WatchServices(ctx context.Context, t eregistry.Target) (ch
addrs = append(addrs, ip+":"+port)
}
reg.addAddrList(al, addrs)
reg.logger.Debug("handle added event succ", zap.String("appName", appName), zap.Any("addrs", addrs))
case watch.Deleted:
addrs := make([]string, 0)
for _, ip := range info.IPs {
addrs = append(addrs, ip+":"+port)
}
reg.deleteAddrList(al, addrs)
reg.logger.Debug("handle deleted event succ", zap.String("appName", appName), zap.Any("addrs", addrs))
case watch.Modified:
addrs := make([]string, 0)
for _, ip := range info.IPs {
addrs = append(addrs, ip+":"+port)
}
reg.updateAddrList(al, addrs)
reg.logger.Debug("handle modified event succ", zap.String("appName", appName), zap.Any("addrs", addrs))
}
out := al.DeepCopy()
reg.logger.Info("update addresses", zap.String("appName", appName), zap.Any("addresses", *out))
Expand Down
1 change: 1 addition & 0 deletions registry/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func Load(key string) *Container {
c.logger.Panic("parse config error", elog.FieldErr(err), elog.FieldKey(key))
return c
}
c.logger.Debug("config info", elog.String("name", c.name), elog.Any("config", c.config))
c.logger = c.logger.With(elog.FieldComponentName(key))
c.name = key
return c
Expand Down

0 comments on commit 48ef6b7

Please sign in to comment.