Skip to content

Commit

Permalink
[DEV-6168] improve debug logging
Browse files Browse the repository at this point in the history
Improve debug logging for entity matchers

Change-Id: I2f8189d2ac82ed8a508ed5ad35411992059a6e47
Signed-off-by: Pavan Kappara <[email protected]>
  • Loading branch information
Pavan Kappara committed Mar 15, 2018
1 parent 6cd78cf commit 2f551a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,12 @@ func (c *Config) getCAName(org string) (string, error) {
}

if _, ok := config.CertificateAuthorities[strings.ToLower(certAuthorityName)]; !ok {
logger.Debugf("Could not find Certificate Authority for [%s], trying with Entity Matchers", certAuthorityName)
_, mappedHost, err := c.tryMatchingCAConfig(strings.ToLower(certAuthorityName))
if err != nil {
return "", errors.WithMessage(err, fmt.Sprintf("CA Server Name %s not found", certAuthorityName))
}
logger.Debugf("Mapped Certificate Authority for [%s] to [%s]", certAuthorityName, mappedHost)
return mappedHost, nil
}

Expand Down Expand Up @@ -480,7 +482,7 @@ func (c *Config) tryMatchingCAConfig(caName string) (*core.CAConfig, string, err
//Get the certAuthorityMatchConfig from mapped host
caConfig, ok := networkConfig.CertificateAuthorities[strings.ToLower(certAuthorityMatchConfig.MappedHost)]
if !ok {
return nil, certAuthorityMatchConfig.MappedHost, errors.WithMessage(err, "failed to load config from matched CertAuthority")
return nil, certAuthorityMatchConfig.MappedHost, errors.New("failed to load config from matched CertAuthority")
}
_, isPortPresentInCAName := c.getPortIfPresent(caName)
//if substitution url is empty, use the same network certAuthority url
Expand Down Expand Up @@ -722,10 +724,12 @@ func (c *Config) OrdererConfig(name string) (*core.OrdererConfig, error) {
}
orderer, ok := config.Orderers[strings.ToLower(name)]
if !ok {
logger.Debugf("Could not find Orderer for [%s], trying with Entity Matchers", name)
matchingOrdererConfig, matchErr := c.tryMatchingOrdererConfig(strings.ToLower(name))
if matchErr != nil {
return nil, errors.WithMessage(matchErr, "unable to find Orderer Config")
}
logger.Debugf("Found matching Orderer Config for [%s]", name)
orderer = *matchingOrdererConfig
}

Expand All @@ -750,10 +754,12 @@ func (c *Config) PeersConfig(org string) ([]core.PeerConfig, error) {
for _, peerName := range peersConfig {
p := config.Peers[strings.ToLower(peerName)]
if err = c.verifyPeerConfig(p, peerName, endpoint.IsTLSEnabled(p.URL)); err != nil {
logger.Debugf("Could not verify Peer for [%s], trying with Entity Matchers", peerName)
matchingPeerConfig, matchErr := c.tryMatchingPeerConfig(peerName)
if matchErr != nil {
return nil, errors.WithMessage(err, "unable to find Peer Config")
}
logger.Debugf("Found a matchingPeerConfig for [%s]", peerName)
p = *matchingPeerConfig
}
if p.TLSCACerts.Path != "" {
Expand Down Expand Up @@ -801,7 +807,7 @@ func (c *Config) tryMatchingPeerConfig(peerName string) (*core.PeerConfig, error
//Get the peerConfig from mapped host
peerConfig, ok := networkConfig.Peers[strings.ToLower(peerMatchConfig.MappedHost)]
if !ok {
return nil, errors.WithMessage(err, "failed to load config from matched Peer")
return nil, errors.New("failed to load config from matched Peer")
}

// Make a copy of GRPC options (as it is manipulated below)
Expand Down Expand Up @@ -902,7 +908,7 @@ func (c *Config) tryMatchingOrdererConfig(ordererName string) (*core.OrdererConf
//Get the ordererConfig from mapped host
ordererConfig, ok := networkConfig.Orderers[strings.ToLower(ordererMatchConfig.MappedHost)]
if !ok {
return nil, errors.WithMessage(err, "failed to load config from matched Orderer")
return nil, errors.New("failed to load config from matched Orderer")
}

// Make a copy of GRPC options (as it is manipulated below)
Expand Down Expand Up @@ -1059,10 +1065,12 @@ func (c *Config) PeerConfigByURL(url string) (*core.PeerConfig, error) {

if matchPeerConfig == nil {
// try to match from entity matchers
logger.Debugf("Could not find Peer for url [%s], trying with Entity Matchers", url)
matchPeerConfig, err = c.tryMatchingPeerConfig(url)
if err != nil {
return nil, errors.WithMessage(err, "No Peer found with the url from config")
}
logger.Debugf("Found MatchingPeerConfig for url [%s]", url)
}

if matchPeerConfig != nil && matchPeerConfig.TLSCACerts.Path != "" {
Expand Down Expand Up @@ -1092,10 +1100,12 @@ func (c *Config) PeerConfig(org string, name string) (*core.PeerConfig, error) {

peerConfig, ok := config.Peers[strings.ToLower(name)]
if !ok {
logger.Debugf("Could not find Peer for [%s], trying with Entity Matchers", name)
matchingPeerConfig, matchErr := c.tryMatchingPeerConfig(strings.ToLower(name))
if matchErr != nil {
return nil, errors.WithMessage(matchErr, "unable to find peer config")
}
logger.Debugf("Found MatchingPeerConfig for [%s]", name)
peerConfig = *matchingPeerConfig
}

Expand All @@ -1113,10 +1123,12 @@ func (c *Config) peerConfig(name string) (*core.PeerConfig, error) {
}
peerConfig, ok := config.Peers[strings.ToLower(name)]
if !ok {
logger.Debugf("Could not find PeerConfig for [%s], trying with Entity Matchers", name)
matchingPeerConfig, matchErr := c.tryMatchingPeerConfig(strings.ToLower(name))
if matchErr != nil {
return nil, errors.WithMessage(matchErr, "unable to find peer config")
}
logger.Debugf("Found MatchingPeerConfig for [%s]", name)
peerConfig = *matchingPeerConfig
}

Expand Down Expand Up @@ -1194,10 +1206,12 @@ func (c *Config) ChannelPeers(name string) ([]core.ChannelPeer, error) {
// Get generic peer configuration
p, ok := netConfig.Peers[strings.ToLower(peerName)]
if !ok {
logger.Debugf("Could not find Peer for [%s], trying with Entity Matchers", peerName)
matchingPeerConfig, matchErr := c.tryMatchingPeerConfig(strings.ToLower(peerName))
if matchErr != nil {
return nil, errors.Errorf("peer config not found for %s", peerName)
}
logger.Debugf("Found matchingPeerConfig for [%s]", peerName)
p = *matchingPeerConfig
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/fab/channel/transactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,22 @@ func orderersFromChannelCfg(ctx context.Client, cfg fab.ChannelCfg) ([]fab.Order
oCfg, ok := ordererDict[target]

if !ok {
logger.Debugf("Failed to get channel Cfg orderer [%s] from ordererDict, now trying orderer Matchers in Entity Matchers", target)
// Try to find a match from entityMatchers config
matchingOrdererConfig, matchErr := ctx.Config().OrdererConfig(strings.ToLower(target))
if matchErr == nil && matchingOrdererConfig != nil {
logger.Debugf("Found matching ordererConfig from entity Matchers for channel Cfg Orderer [%s]", target)
oCfg = *matchingOrdererConfig
ok = true
}

}
if !ok {
logger.Debugf("Unable to find matching ordererConfig from entity Matchers for channel Cfg Orderer [%s]", target)
oCfg = core.OrdererConfig{
URL: target,
}
logger.Debugf("Created a new OrdererConfig with URL as [%s]", target)
}

o, err := ctx.InfraProvider().CreateOrdererFromConfig(&oCfg)
Expand Down

0 comments on commit 2f551a2

Please sign in to comment.