<commit_before>/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.fuse;

import alluxio.ProjectConstants;
import alluxio.RuntimeConstants;
import alluxio.client.file.FileSystem;
import alluxio.client.file.FileSystemContext;
import alluxio.conf.AlluxioConfiguration;
import alluxio.conf.InstancedConfiguration;
import alluxio.conf.PropertyKey;
import alluxio.jnifuse.FuseException;
import alluxio.retry.RetryUtils;
import alluxio.util.io.FileUtils;

import com.google.common.base.Preconditions;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;

/**
 * Main entry point to Alluxio-FUSE.
 */
@ThreadSafe
public final class AlluxioFuse {
  private static final Logger LOG = LoggerFactory.getLogger(AlluxioFuse.class);

  private static final Option MOUNT_POINT_OPTION = Option.builder("m")
      .hasArg()
      .required(true)
      .longOpt("mount-point")
      .desc("Desired local mount point for alluxio-fuse.")
      .build();

  private static final Option ALLUXIO_ROOT_OPTION = Option.builder("r")
      .hasArg()
      .required(true)
      .longOpt("alluxio-root")
      .desc("Path within alluxio that will be used as the root of the FUSE mount "
          + "(e.g., /users/foo; defaults to /)")
      .build();

  private static final Option HELP_OPTION = Option.builder("h")
      .required(false)
      .desc("Print this help message")
      .build();

  private static final Option FUSE_MOUNT_OPTION = Option.builder("o")
      .valueSeparator(',')
      .required(false)
      .hasArgs()
      .desc("FUSE mount options")
      .build();

  private static final Options OPTIONS = new Options()
      .addOption(MOUNT_POINT_OPTION)
      .addOption(ALLUXIO_ROOT_OPTION)
      .addOption(HELP_OPTION)
      .addOption(FUSE_MOUNT_OPTION);

  // prevent instantiation
  private AlluxioFuse() {}

  /**
   * Running this class will mount the file system according to the options passed to this function
   * {@link #parseOptions(String[], AlluxioConfiguration)}. The user-space fuse application will
   * stay on the foreground and keep the file system mounted. The user can unmount the file system
   * by gracefully killing (SIGINT) the process.
   *
   * @param args arguments to run the command line
   */
  public static void main(String[] args) {
    LOG.info("Alluxio version: {}-{}", RuntimeConstants.VERSION, ProjectConstants.REVISION);
    AlluxioConfiguration conf = InstancedConfiguration.defaults();
    FileSystemContext fsContext = FileSystemContext.create(conf);
    try {
      InetSocketAddress confMasterAddress =
          fsContext.getMasterClientContext().getConfMasterInquireClient().getPrimaryRpcAddress();
      RetryUtils.retry("load cluster default configuration with master " + confMasterAddress,
          () -> fsContext.getClientContext().loadConfIfNotLoaded(confMasterAddress),
          RetryUtils.defaultClientRetry(
              conf.getDuration(PropertyKey.USER_RPC_RETRY_MAX_DURATION),
              conf.getDuration(PropertyKey.USER_RPC_RETRY_BASE_SLEEP_MS),
              conf.getDuration(PropertyKey.USER_RPC_RETRY_MAX_SLEEP_MS)));
    } catch (IOException e) {
      LOG.warn("Failed to load cluster default configuration for Fuse process. "
          + "Proceed with local configuration for FUSE: {}", e.toString());
    }
    conf = fsContext.getClusterConf();
    final FuseMountOptions opts = parseOptions(args, conf);
    if (opts == null) {
      System.exit(1);
    }
    try (FileSystem fs = FileSystem.Factory.create(fsContext)) {
      launchFuse(fs, conf, opts, true);
    } catch (IOException e) {
      LOG.error(e.getMessage());
      System.exit(-1);
    }
  }
<commit_msg>Add metrics sink for standalone fuse process<commit_after>/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.fuse;

import alluxio.ProjectConstants;
import alluxio.RuntimeConstants;
import alluxio.client.file.FileSystem;
import alluxio.client.file.FileSystemContext;
import alluxio.conf.AlluxioConfiguration;
import alluxio.conf.InstancedConfiguration;
import alluxio.conf.PropertyKey;
import alluxio.jnifuse.FuseException;
import alluxio.metrics.MetricsSystem;
import alluxio.retry.RetryUtils;
import alluxio.util.CommonUtils;
import alluxio.util.io.FileUtils;

import com.google.common.base.Preconditions;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;

/**
 * Main entry point to Alluxio-FUSE.
 */
@ThreadSafe
public final class AlluxioFuse {
  private static final Logger LOG = LoggerFactory.getLogger(AlluxioFuse.class);

  private static final Option MOUNT_POINT_OPTION = Option.builder("m")
      .hasArg()
      .required(true)
      .longOpt("mount-point")
      .desc("Desired local mount point for alluxio-fuse.")
      .build();

  private static final Option ALLUXIO_ROOT_OPTION = Option.builder("r")
      .hasArg()
      .required(true)
      .longOpt("alluxio-root")
      .desc("Path within alluxio that will be used as the root of the FUSE mount "
          + "(e.g., /users/foo; defaults to /)")
      .build();

  private static final Option HELP_OPTION = Option.builder("h")
      .required(false)
      .desc("Print this help message")
      .build();

  private static final Option FUSE_MOUNT_OPTION = Option.builder("o")
      .valueSeparator(',')
      .required(false)
      .hasArgs()
      .desc("FUSE mount options")
      .build();

  private static final Options OPTIONS = new Options()
      .addOption(MOUNT_POINT_OPTION)
      .addOption(ALLUXIO_ROOT_OPTION)
      .addOption(HELP_OPTION)
      .addOption(FUSE_MOUNT_OPTION);

  // prevent instantiation
  private AlluxioFuse() {}

  /**
   * Running this class will mount the file system according to the options passed to this function
   * {@link #parseOptions(String[], AlluxioConfiguration)}. The user-space fuse application will
   * stay on the foreground and keep the file system mounted. The user can unmount the file system
   * by gracefully killing (SIGINT) the process.
   *
   * @param args arguments to run the command line
   */
  public static void main(String[] args) {
    LOG.info("Alluxio version: {}-{}", RuntimeConstants.VERSION, ProjectConstants.REVISION);
    AlluxioConfiguration conf = InstancedConfiguration.defaults();
    FileSystemContext fsContext = FileSystemContext.create(conf);
    try {
      InetSocketAddress confMasterAddress =
          fsContext.getMasterClientContext().getConfMasterInquireClient().getPrimaryRpcAddress();
      RetryUtils.retry("load cluster default configuration with master " + confMasterAddress,
          () -> fsContext.getClientContext().loadConfIfNotLoaded(confMasterAddress),
          RetryUtils.defaultClientRetry(
              conf.getDuration(PropertyKey.USER_RPC_RETRY_MAX_DURATION),
              conf.getDuration(PropertyKey.USER_RPC_RETRY_BASE_SLEEP_MS),
              conf.getDuration(PropertyKey.USER_RPC_RETRY_MAX_SLEEP_MS)));
    } catch (IOException e) {
      LOG.warn("Failed to load cluster default configuration for Fuse process. "
          + "Proceed with local configuration for FUSE: {}", e.toString());
    }
    conf = fsContext.getClusterConf();
    final FuseMountOptions opts = parseOptions(args, conf);
    if (opts == null) {
      System.exit(1);
    }
    CommonUtils.PROCESS_TYPE.set(CommonUtils.ProcessType.CLIENT);
    MetricsSystem.startSinks(conf.get(PropertyKey.METRICS_CONF_FILE));
    try (FileSystem fs = FileSystem.Factory.create(fsContext)) {
      launchFuse(fs, conf, opts, true);
    } catch (IOException e) {
      LOG.error(e.getMessage());
      System.exit(-1);
    }
  }

{'fraction_non_alphanumeric': 0.10045040326804232, 'fraction_numerical': 0.0016759191369016444, 'mean_word_length': 3.846700507614213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6539224', 'n_tokens_mistral': 2758, 'n_tokens_neox': 2761, 'n_words': 730}