github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/docs/source/operations_service.rst (about)

     1  The Operations Service
     2  ======================
     3  
     4  The peer and the orderer host an HTTP server that offers a RESTful "operations"
     5  API. This API is unrelated to the Fabric network services and is intended to be
     6  used by operators, not administrators or "users" of the network.
     7  
     8  The API exposes the following capabilities:
     9  
    10  - Log level management
    11  - Health checks
    12  - Prometheus target for operational metrics (when configured)
    13  - Endpoint for retrieving version information
    14  
    15  Configuring the Operations Service
    16  ----------------------------------
    17  
    18  The operations service requires two basic pieces of configuration:
    19  
    20  - The **address** and **port** to listen on.
    21  - The **TLS certificates** and **keys** to use for authentication and encryption.
    22    Note, **these certificates should be generated by a separate and dedicated CA**.
    23    Do not use a CA that has generated certificates for any organizations
    24    in any channels.
    25  
    26  Peer
    27  ~~~~
    28  
    29  For each peer, the operations server can be configured in the ``operations``
    30  section of ``core.yaml``:
    31  
    32  .. code:: yaml
    33  
    34    operations:
    35      # host and port for the operations server
    36      listenAddress: 127.0.0.1:9443
    37  
    38      # TLS configuration for the operations endpoint
    39      tls:
    40        # TLS enabled
    41        enabled: true
    42  
    43        # path to PEM encoded server certificate for the operations server
    44        cert:
    45          file: tls/server.crt
    46  
    47        # path to PEM encoded server key for the operations server
    48        key:
    49          file: tls/server.key
    50  
    51        # most operations service endpoints require client authentication when TLS
    52        # is enabled. clientAuthRequired requires client certificate authentication
    53        # at the TLS layer to access all resources.
    54        clientAuthRequired: false
    55  
    56        # paths to PEM encoded ca certificates to trust for client authentication
    57        clientRootCAs:
    58          files: []
    59  
    60  The ``listenAddress`` key defines the host and port that the operation server
    61  will listen on. If the server should listen on all addresses, the host portion
    62  can be omitted.
    63  
    64  The ``tls`` section is used to indicate whether or not TLS is enabled for the
    65  operations service, the location of the service's certificate and private key,
    66  and the locations of certificate authority root certificates that should be
    67  trusted for client authentication. When ``enabled`` is true, most of the operations
    68  service endpoints require client authentication, therefore
    69  ``clientRootCAs.files`` must be set. When ``clientAuthRequired`` is ``true``,
    70  the TLS layer will require clients to provide a certificate for authentication
    71  on every request. See Operations Security section below for more details.
    72  
    73  Orderer
    74  ~~~~~~~
    75  
    76  For each orderer, the operations server can be configured in the `Operations`
    77  section of ``orderer.yaml``:
    78  
    79  .. code:: yaml
    80  
    81    Operations:
    82      # host and port for the operations server
    83      ListenAddress: 127.0.0.1:8443
    84  
    85      # TLS configuration for the operations endpoint
    86      TLS:
    87        # TLS enabled
    88        Enabled: true
    89  
    90        # PrivateKey: PEM-encoded tls key for the operations endpoint
    91        PrivateKey: tls/server.key
    92  
    93        # Certificate governs the file location of the server TLS certificate.
    94        Certificate: tls/server.crt
    95  
    96        # Paths to PEM encoded ca certificates to trust for client authentication
    97        ClientRootCAs: []
    98  
    99        # Most operations service endpoints require client authentication when TLS
   100        # is enabled. ClientAuthRequired requires client certificate authentication
   101        # at the TLS layer to access all resources.
   102        ClientAuthRequired: false
   103  
   104  The ``ListenAddress`` key defines the host and port that the operations server
   105  will listen on. If the server should listen on all addresses, the host portion
   106  can be omitted.
   107  
   108  The ``TLS`` section is used to indicate whether or not TLS is enabled for the
   109  operations service, the location of the service's certificate and private key,
   110  and the locations of certificate authority root certificates that should be
   111  trusted for client authentication.   When ``Enabled`` is true, most of the operations
   112  service endpoints require client authentication, therefore
   113  ``RootCAs`` must be set. When ``ClientAuthRequired`` is ``true``,
   114  the TLS layer will require clients to provide a certificate for authentication
   115  on every request. See Operations Security section below for more details.
   116  
   117  Operations Security
   118  ~~~~~~~~~~~~~~~~~~~
   119  
   120  As the operations service is focused on operations and intentionally unrelated
   121  to the Fabric network, it does not use the Membership Services Provider for
   122  access control. Instead, the operations service relies entirely on mutual TLS with
   123  client certificate authentication.
   124  
   125  When TLS is disabled, authorization is bypassed and any client that can
   126  connect to the operations endpoint will be able to use the API.
   127  
   128  When TLS is enabled, a valid client certificate must be provided in order to
   129  access the logging and metrics services. The health check and version services
   130  only require a valid client certificate when ``clientAuthRequired`` is enabled,
   131  since these services are often used by network operators and only provide read-only information.
   132  
   133  When ``clientAuthRequired`` is enabled, the TLS layer will also require
   134  a valid client certificate regardless of the resource being accessed.
   135  
   136  Log Level Management
   137  --------------------
   138  
   139  The operations service provides a ``/logspec`` resource that operators can use to
   140  manage the active logging spec for a peer or orderer. The resource is a
   141  conventional REST resource and supports ``GET`` and ``PUT`` requests.
   142  
   143  When a ``GET /logspec`` request is received by the operations service, it will
   144  respond with a JSON payload that contains the current logging specification:
   145  
   146  .. code:: json
   147  
   148    {"spec":"info"}
   149  
   150  When a ``PUT /logspec`` request is received by the operations service, it will
   151  read the body as a JSON payload. The payload must consist of a single attribute
   152  named ``spec``.
   153  
   154  .. code:: json
   155  
   156    {"spec":"chaincode=debug:info"}
   157  
   158  If the spec is activated successfully, the service will respond with a ``204 "No Content"``
   159  response. If an error occurs, the service will respond with a ``400 "Bad Request"``
   160  and an error payload:
   161  
   162  .. code:: json
   163  
   164    {"error":"error message"}
   165  
   166  When TLS is enabled, a valid client certificate is required to use this
   167  service regardless of whether ``clientAuthRequired`` is set to ``true`` at the TLS level.
   168  
   169  Metrics
   170  -------
   171  
   172  Some components of the Fabric peer and orderer expose metrics that can help
   173  provide insight into the behavior of the system. Operators and administrators
   174  can use this information to better understand how the system is performing
   175  over time.
   176  
   177  Configuring Metrics
   178  ~~~~~~~~~~~~~~~~~~~
   179  
   180  Fabric provides two ways to expose metrics: a **pull** model based on Prometheus
   181  and a **push** model based on StatsD.
   182  
   183  Prometheus
   184  ~~~~~~~~~~
   185  
   186  A typical Prometheus deployment scrapes metrics by requesting them from an HTTP
   187  endpoint exposed by instrumented targets. As Prometheus is responsible for
   188  requesting the metrics, it is considered a pull system.
   189  
   190  When configured, a Fabric peer or orderer will present a ``/metrics`` resource
   191  on the operations service.
   192  
   193  When TLS is enabled, a valid client certificate is required to use this
   194  service regardless of whether ``clientAuthRequired`` is set to ``true`` at the TLS level.
   195  
   196  Peer
   197  ^^^^
   198  
   199  A peer can be configured to expose a ``/metrics`` endpoint for Prometheus to
   200  scrape by setting the metrics provider to ``prometheus`` in the ``metrics`` section
   201  of ``core.yaml``.
   202  
   203  .. code:: yaml
   204  
   205    metrics:
   206      provider: prometheus
   207  
   208  Orderer
   209  ^^^^^^^
   210  
   211  An orderer can be configured to expose a ``/metrics`` endpoint for Prometheus to
   212  scrape by setting the metrics provider to ``prometheus`` in the ``Metrics``
   213  section of ``orderer.yaml``.
   214  
   215  .. code:: yaml
   216  
   217    Metrics:
   218      Provider: prometheus
   219  
   220  StatsD
   221  ~~~~~~
   222  
   223  StatsD is a simple statistics aggregation daemon. Metrics are sent to a
   224  ``statsd`` daemon where they are collected, aggregated, and pushed to a backend
   225  for visualization and alerting. As this model requires instrumented processes
   226  to send metrics data to StatsD, this is considered a push system.
   227  
   228  Peer
   229  ^^^^
   230  
   231  A peer can be configured to send metrics to StatsD by setting the metrics
   232  provider to ``statsd`` in the ``metrics`` section of ``core.yaml``. The ``statsd``
   233  subsection must also be configured with the address of the StatsD daemon, the
   234  network type to use (``tcp`` or ``udp``), and how often to send the metrics. An
   235  optional ``prefix`` may be specified to help differentiate the source of the
   236  metrics --- for example, differentiating metrics coming from separate peers ---
   237  that would be prepended to all generated metrics.
   238  
   239  .. code:: yaml
   240  
   241    metrics:
   242      provider: statsd
   243      statsd:
   244        network: udp
   245        address: 127.0.0.1:8125
   246        writeInterval: 10s
   247        prefix: peer-0
   248  
   249  Orderer
   250  ^^^^^^^
   251  
   252  An orderer can be configured to send metrics to StatsD by setting the metrics
   253  provider to ``statsd`` in the ``Metrics`` section of ``orderer.yaml``. The ``Statsd``
   254  subsection must also be configured with the address of the StatsD daemon, the
   255  network type to use (``tcp`` or ``udp``), and how often to send the metrics. An
   256  optional ``prefix`` may be specified to help differentiate the source of the
   257  metrics.
   258  
   259  .. code:: yaml
   260  
   261    Metrics:
   262        Provider: statsd
   263        Statsd:
   264          Network: udp
   265          Address: 127.0.0.1:8125
   266          WriteInterval: 30s
   267          Prefix: org-orderer
   268  
   269  For a look at the different metrics that are generated, check out
   270  :doc:`metrics_reference`.
   271  
   272  Health Checks
   273  -------------
   274  
   275  The operations service provides a ``/healthz`` resource that operators can use to
   276  help determine the liveness and health of peers and orderers. The resource is
   277  a conventional REST resource that supports GET requests. The implementation is
   278  intended to be compatible with the liveness probe model used by Kubernetes but
   279  can be used in other contexts.
   280  
   281  When a ``GET /healthz`` request is received, the operations service will call all
   282  registered health checkers for the process to ensure all registered services and
   283  dependencies are available. When all of the health checkers
   284  return successfully, the operations service will respond with a ``200 "OK"`` and a
   285  JSON body:
   286  
   287  .. code:: json
   288  
   289    {
   290      "status": "OK",
   291      "time": "2009-11-10T23:00:00Z"
   292    }
   293  
   294  If one or more of the health checkers returns an error, the operations service
   295  will respond with a ``503 "Service Unavailable"`` and a JSON body that includes
   296  information about which health checker failed:
   297  
   298  .. code:: json
   299  
   300    {
   301      "status": "Service Unavailable",
   302      "time": "2009-11-10T23:00:00Z",
   303      "failed_checks": [
   304        {
   305          "component": "docker",
   306          "reason": "failed to connect to Docker daemon: invalid endpoint"
   307        }
   308      ]
   309    }
   310  
   311  The peer has the following health checks available:
   312  
   313  - Docker daemon health check (if a Docker endpoint is configured for chaincodes)
   314  - CouchDB health check (if CouchDB is configured as the state database)
   315  
   316  When TLS is enabled, a valid client certificate is not required to use this
   317  service unless ``clientAuthRequired`` is set to ``true``.
   318  
   319  Version
   320  -------
   321  
   322  The orderer and peer both expose a ``/version`` endpoint. This endpoint
   323  serves a JSON document containing the orderer or peer version and the commit
   324  SHA on which the release was created.
   325  
   326  When TLS is enabled, a valid client certificate is not required to use this
   327  service unless ``clientAuthRequired`` is set to ``true``.
   328  
   329  .. Licensed under Creative Commons Attribution 4.0 International License
   330     https://creativecommons.org/licenses/by/4.0/