Publishes metrics to a file in JSON format.

        This method is called by the Snap deamon during the collection phase
        of the execution of a Snap workflow.

        In this example we are writing the metrics to a file in json format.
        We obtain the path to the file through the config (`ConfigMap`) arg.

        Args:
            metrics (obj:`list` of :obj:`snap_plugin.v1.Metric`):
                List of metrics to be collected.

        Returns:
            :obj:`list` of :obj:`snap_plugin.v1.Metric`:
                List of collected metrics.

def publish(self, metrics, config):
        """Publishes metrics to a file in JSON format.

        This method is called by the Snap deamon during the collection phase
        of the execution of a Snap workflow.

        In this example we are writing the metrics to a file in json format.
        We obtain the path to the file through the config (`ConfigMap`) arg.

        Args:
            metrics (obj:`list` of :obj:`snap_plugin.v1.Metric`):
                List of metrics to be collected.

        Returns:
            :obj:`list` of :obj:`snap_plugin.v1.Metric`:
                List of collected metrics.
        """
        if len(metrics) > 0:
            with open(config["file"], 'a') as outfile:
                for metric in metrics:
                    outfile.write(
                        json_format.MessageToJson(
                            metric._pb, including_default_value_fields=True))