Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/add-logs #2

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading