github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/views/reports/containers/range/allocator.tsx (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import _ from "lodash";
    12  import React from "react";
    13  
    14  import * as protos from "src/js/protos";
    15  import { CachedDataReducerState } from "src/redux/cachedDataReducer";
    16  import { REMOTE_DEBUGGING_ERROR_TEXT } from "src/util/constants";
    17  import Print from "src/views/reports/containers/range/print";
    18  import Loading from "src/views/shared/components/loading";
    19  
    20  interface AllocatorOutputProps {
    21    allocator: CachedDataReducerState<protos.cockroach.server.serverpb.AllocatorRangeResponse>;
    22  }
    23  
    24  export default class AllocatorOutput extends React.Component<AllocatorOutputProps, {}> {
    25    renderContent = () => {
    26      const { allocator } = this.props;
    27  
    28      if (allocator && (_.isEmpty(allocator.data) || _.isEmpty(allocator.data.dry_run))) {
    29        return (
    30          <div>
    31            No simulated allocator output was returned.
    32          </div>
    33        );
    34      }
    35  
    36      return (
    37        <table className="allocator-table">
    38          <tbody>
    39            <tr className="allocator-table__row allocator-table__row--header">
    40              <th className="allocator-table__cell allocator-table__cell--header">Timestamp</th>
    41              <th className="allocator-table__cell allocator-table__cell--header">Message</th>
    42            </tr>
    43            {
    44              _.map(allocator.data.dry_run.events, (event, key) => (
    45                <tr key={key} className="allocator-table__row">
    46                  <td className="allocator-table__cell allocator-table__cell--date">{Print.Timestamp(event.time)}</td>
    47                  <td className="allocator-table__cell">{event.message}</td>
    48                </tr>
    49              ))
    50            }
    51          </tbody>
    52        </table>
    53      );
    54    }
    55  
    56    render() {
    57      const { allocator } = this.props;
    58  
    59      // TODO(couchand): This is a really myopic way to check for this particular
    60      // case, but making major changes to the CachedDataReducer or util.api seems
    61      // fraught at this point.  We should revisit this soon.
    62      if (allocator && allocator.lastError && allocator.lastError.message === "Forbidden") {
    63        return (
    64          <div>
    65            <h2 className="base-heading">Simulated Allocator Output</h2>
    66            { REMOTE_DEBUGGING_ERROR_TEXT }
    67          </div>
    68        );
    69      }
    70  
    71      let fromNodeID = "";
    72      if (allocator && !_.isEmpty(allocator.data)) {
    73        fromNodeID = ` (from n${allocator.data.node_id.toString()})`;
    74      }
    75  
    76      return (
    77        <div>
    78          <h2 className="base-heading">Simulated Allocator Output{fromNodeID}</h2>
    79          <Loading
    80            loading={!allocator || allocator.inFlight}
    81            error={allocator && allocator.lastError}
    82            render={this.renderContent}
    83          />
    84        </div>
    85      );
    86    }
    87  }