Skip to content

Commit 7a9d7dc

Browse files
author
Jason Yellick
committed
[FAB-5522] Log policy manager path for GetPolicy
The configtx processing looks up policies by relative name, which triggers finding the right policy manager, then querying the relative name. The problem with this however, is that the logs only show the relative name, which can make debugging challenging. Change-Id: I49ce4cba89a10a433a932f5e61f90a38ef34534a Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 3e4ae31 commit 7a9d7dc

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

common/configtx/update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (cm *configManager) verifyDeltaSet(deltaSet map[string]comparable, signedDa
8181
}
8282

8383
for key, value := range deltaSet {
84+
logger.Debugf("Processing change to key: %s", key)
8485
if err := validateModPolicy(value.modPolicy()); err != nil {
8586
return fmt.Errorf("invalid mod_policy for element %s: %s", key, err)
8687
}

common/policies/policy.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package policies
@@ -126,8 +116,9 @@ type policyConfig struct {
126116
// In general, it should only be referenced as an Impl for the configtx.ConfigManager
127117
type ManagerImpl struct {
128118
parent *ManagerImpl
129-
basePath string
130-
fqPrefix string
119+
basePath string // The group level path
120+
fqPrefix string // If this manager is treated as the root, the fully qualified prefix for policy names
121+
fqPath string // The true absolute path, taking parents into consideration
131122
providers map[int32]Provider
132123
config *policyConfig
133124
pendingConfig map[interface{}]*policyConfig
@@ -148,6 +139,7 @@ func NewManagerImpl(basePath string, providers map[int32]Provider) *ManagerImpl
148139
return &ManagerImpl{
149140
basePath: basePath,
150141
fqPrefix: PathSeparator + basePath + PathSeparator,
142+
fqPath: PathSeparator + basePath, // Overridden after construction in the sub-manager case
151143
providers: providers,
152144
config: &policyConfig{
153145
policies: make(map[string]Policy),
@@ -223,7 +215,7 @@ func (pm *ManagerImpl) GetPolicy(id string) (Policy, bool) {
223215
return rejectPolicy(relpath), false
224216
}
225217
if logger.IsEnabledFor(logging.DEBUG) {
226-
logger.Debugf("Returning policy %s for evaluation", relpath)
218+
logger.Debugf("Returning policy %s from manager %s for evaluation", relpath, pm.fqPath)
227219
}
228220
return policy, true
229221
}
@@ -247,6 +239,13 @@ func (pm *ManagerImpl) BeginPolicyProposals(tx interface{}, groups []string) ([]
247239
for i, group := range groups {
248240
newManager := NewManagerImpl(group, pm.providers)
249241
newManager.parent = pm
242+
mi := newManager
243+
var fqPath []string
244+
for mi != nil {
245+
fqPath = append([]string{PathSeparator, mi.basePath}, fqPath...)
246+
mi = mi.parent
247+
}
248+
newManager.fqPath = strings.Join(fqPath, "")
250249
pendingConfig.managers[group] = newManager
251250
managers[i] = newManager
252251
}

common/policies/policy_test.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
/*
2-
Copyright IBM Corp. 2017 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package policies
188

199
import (
10+
"fmt"
2011
"testing"
2112

2213
cb "github.com/hyperledger/fabric/protos/common"
@@ -192,3 +183,19 @@ func TestNestedManager(t *testing.T) {
192183
}
193184
}
194185
}
186+
187+
func TestFQPathName(t *testing.T) {
188+
fqPath := []string{"base", "nest1", "nest2"}
189+
m := NewManagerImpl(fqPath[0], defaultProviders())
190+
nesting1, err := m.BeginPolicyProposals(t, []string{fqPath[1]})
191+
assert.NoError(t, err)
192+
assert.Len(t, nesting1, 1)
193+
194+
nesting2, err := nesting1[0].BeginPolicyProposals(t, []string{fqPath[2]})
195+
assert.NoError(t, err)
196+
assert.Len(t, nesting2, 1)
197+
198+
assert.Equal(t, fmt.Sprintf("/%s/%s/%s", fqPath[0], fqPath[1], fqPath[2]), nesting2[0].(*ManagerImpl).fqPath)
199+
assert.Equal(t, fmt.Sprintf("/%s/%s", fqPath[0], fqPath[1]), nesting1[0].(*ManagerImpl).fqPath)
200+
assert.Equal(t, fmt.Sprintf("/%s", fqPath[0]), m.fqPath)
201+
}

0 commit comments

Comments
 (0)