<commit_before>package com.github.secondbase.consul.registration;

import com.github.secondbase.consul.ConsulModule;
import com.github.secondbase.core.SecondBase;
import com.github.secondbase.core.SecondBaseException;
import com.github.secondbase.core.config.SecondBaseModule;
import com.github.secondbase.webconsole.HttpWebConsole;

/**
 * Consul service registration for Prometheus WebConsole widget.
 */
public final class ConsulRegistrationMetricsWebConsole implements SecondBaseModule {

    private final HttpWebConsole webConsole;
    private final ConsulModule consulModule;

    @Override
    public void load(final SecondBase secondBase) {
        // nothing to configure
    }

    @Override
    public void init() throws SecondBaseException {
        consulModule.registerServiceInConsul(
                SecondBase.serviceName,
                webConsole.getPort(),
                SecondBase.environment,
                "/healthz",
                29L,
                "metrics"
        );
    }

    public ConsulRegistrationMetricsWebConsole(
            final HttpWebConsole webConsole,
            final ConsulModule consulModule) {
        this.webConsole = webConsole;<commit_msg>Only register metrics endpoint with valid flags (#59)<commit_after>package com.github.secondbase.consul.registration;

import com.github.secondbase.consul.ConsulModule;
import com.github.secondbase.consul.ConsulModuleConfiguration;
import com.github.secondbase.core.SecondBase;
import com.github.secondbase.core.SecondBaseException;
import com.github.secondbase.core.config.SecondBaseModule;
import com.github.secondbase.webconsole.HttpWebConsole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Consul service registration for Prometheus WebConsole widget.
 */
public final class ConsulRegistrationMetricsWebConsole implements SecondBaseModule {

    private static final Logger LOG = LoggerFactory.getLogger(
            ConsulRegistrationMetricsWebConsole.class.getName());

    private final HttpWebConsole webConsole;
    private final ConsulModule consulModule;

    @Override
    public void load(final SecondBase secondBase) {
        // nothing to configure
    }

    @Override
    public void init() throws SecondBaseException {
        if (SecondBase.serviceName.isEmpty()) {
            LOG.info("No service name defined. Nothing to register yet.");
            return;
        }
        if (ConsulModuleConfiguration.servicePort == 0) {
            LOG.error("Service port needs to be defined in order to register a service in consul.");
            return;
        }
        if (SecondBase.environment.isEmpty()) {
            LOG.error("Environment needs to be defined in order to register a service in consul.");
            return;
        }
        if (ConsulModuleConfiguration.healthCheckPath.isEmpty()) {
            LOG.error("Health check path needs to be defined in order to register a service in "
                    + "consul.");
            return;
        }
        consulModule.registerServiceInConsul(
                SecondBase.serviceName,
                webConsole.getPort(),
                SecondBase.environment,
                "/healthz",
                29L,
                "metrics"
        );
    }

    public ConsulRegistrationMetricsWebConsole(
            final HttpWebConsole webConsole,
            final ConsulModule consulModule) {
        this.webConsole = webConsole;
{'fraction_non_alphanumeric': 0.07383720930232558, 'fraction_numerical': 0.002616279069767442, 'mean_word_length': 2.676282051282051, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '686314', 'n_tokens_mistral': 861, 'n_tokens_neox': 829, 'n_words': 212}