<commit_before>/*
 * Copyright 2012-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.codekvast.login.bootstrap;

import com.amazonaws.services.cloudwatch.AmazonCloudWatchAsync;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClientBuilder;
import io.codekvast.common.bootstrap.CodekvastCommonSettings;
import io.micrometer.cloudwatch.CloudWatchConfig;
import io.micrometer.cloudwatch.CloudWatchMeterRegistry;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Configure export of metrics to AWS CloudWatch.
 *
 * This class will not be needed once Spring Boot supports auto-configuration also of CloudWatch.
 */
@Configuration
@ConditionalOnProperty(prefix = "management.metrics.export.cloudwatch", name = "enabled", havingValue = "true", matchIfMissing = true)
public class CloudWatchMetricsConfiguration {

	@Bean
	public CloudWatchConfig cloudWatchConfig(CloudWatchProperties cloudWatchProperties) {
		return new CloudWatchPropertiesConfigAdapter(cloudWatchProperties);
	}

	@Bean
    public AmazonCloudWatchAsync amazonCloudWatchAsync(CloudWatchProperties cloudWatchProperties) {
        return AmazonCloudWatchAsyncClientBuilder.standard()
                                                 .withRegion(cloudWatchProperties.getAwsRegion())
                                                 .build();
    }

	@Bean
	public CloudWatchMeterRegistry cloudWatchMeterRegistry(CloudWatchConfig cloudWatchConfig, Clock clock, AmazonCloudWatchAsync amazonCloudWatchAsync) {
		return new CloudWatchMeterRegistry(cloudWatchConfig, clock, amazonCloudWatchAsync);
	}

    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags(
        @Value("${spring.application.name}") String applicationName,
        CodekvastCommonSettings codekvastSettings) {
        return registry -> registry.config().commonTags("application", applicationName,
                                                        "host", codekvastSettings.getDnsCname());
    }
}<commit_msg>Strip after dots in CloudWatch metrics host name.<commit_after>/*
 * Copyright 2012-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.codekvast.login.bootstrap;

import com.amazonaws.services.cloudwatch.AmazonCloudWatchAsync;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClientBuilder;
import io.codekvast.common.bootstrap.CodekvastCommonSettings;
import io.micrometer.cloudwatch.CloudWatchConfig;
import io.micrometer.cloudwatch.CloudWatchMeterRegistry;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Configure export of metrics to AWS CloudWatch.
 *
 * This class will not be needed once Spring Boot supports auto-configuration also of CloudWatch.
 */
@Configuration
@ConditionalOnProperty(prefix = "management.metrics.export.cloudwatch", name = "enabled", havingValue = "true", matchIfMissing = true)
public class CloudWatchMetricsConfiguration {

	@Bean
	public CloudWatchConfig cloudWatchConfig(CloudWatchProperties cloudWatchProperties) {
		return new CloudWatchPropertiesConfigAdapter(cloudWatchProperties);
	}

	@Bean
    public AmazonCloudWatchAsync amazonCloudWatchAsync(CloudWatchProperties cloudWatchProperties) {
        return AmazonCloudWatchAsyncClientBuilder.standard()
                                                 .withRegion(cloudWatchProperties.getAwsRegion())
                                                 .build();
    }

	@Bean
	public CloudWatchMeterRegistry cloudWatchMeterRegistry(CloudWatchConfig cloudWatchConfig, Clock clock, AmazonCloudWatchAsync amazonCloudWatchAsync) {
		return new CloudWatchMeterRegistry(cloudWatchConfig, clock, amazonCloudWatchAsync);
	}

    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags(
        @Value("${spring.application.name}") String applicationName,
        CodekvastCommonSettings codekvastSettings) {
        return registry -> registry.config().commonTags("application", applicationName,
                                                        "host", codekvastSettings.getDnsCname().replaceAll("\\..*$", ""));
    }
}
{'fraction_non_alphanumeric': 0.07700118463360975, 'fraction_numerical': 0.004061600947706888, 'mean_word_length': 4.234720992028343, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2148898', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1410, 'n_words': 387}