hyperledger / caliper

A blockchain benchmark framework to measure performance of multiple blockchain solutions https://wiki.hyperledger.org/display/caliper
https://hyperledger.github.io/caliper/
Apache License 2.0
650 stars 403 forks source link

docker monitor fails in caliper 0.5.0 when referencing a remote docker container #1493

Open davidkel opened 1 year ago

davidkel commented 1 year ago

The following error is received

could not start monitors: typererror: cannot read properties of undefined {hasOwnproperty}

if you specify an entry for docker monitoring such as

monitors:
  resource:
  - module: docker
    options:
      interval: 5
      containers:
      - peer0.org1.example.com
      - peer1.org1.example.com
      - orderer.example.com
      - orderer2.example.com
      - http://10.0.0.252:9051/peer0.org2.example.com

This is due to this line in the monitor-docker.js https://github.com/hyperledger/caliper/blob/943ab2a22872639f39ccb36f8baf94b2863e21c6/packages/caliper-core/lib/manager/monitors/monitor-docker.js#L75

which is

    async findContainers() {
        this.containers = [];
        let filterName = {};
        // Split docker items that are local or remote
        if (this.options.hasOwnProperty('containers')) {
            for (let key in this.options.containers) {
                let container = this.options.containers[key];
                if (container.indexOf('http://') === 0) {
                    // Is remote
                    let remote = URL.parse(container, true);
                    if (remote.hostname === null || remote.port === null || remote.pathname === '/') {
                        Logger.warn('unrecognized host, ' + container);
                    } else if (filterName.remote.hasOwnProperty(remote.hostname)) {  <---- BUG HERE
                        filterName[remote.hostname].containers.push(remote.pathname);
                    } else {
                        filterName[remote.hostname] = { port: remote.port, containers: [remote.pathname] };
                    }
                } else {
                    // Is local
                    if (filterName.hasOwnProperty('localhost')) {
                        filterName.localhost.containers.push(container);
                    } else {
                        filterName.localhost = { containers: [container] };
                    }
                }
            }
        }

We see that there is no property remote on filterName. It should be a simple fix just to remove the .remote part