Skip to content

Commit

Permalink
Merge pull request kruize#1276 from msvinaykumar/notificationfix
Browse files Browse the repository at this point in the history
Kruize Notification prod fix
  • Loading branch information
dinogun authored Sep 3, 2024
2 parents 93e2b82 + fd74b6b commit 17b23ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.autotune.utils.MetricsConfig;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Tags;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Timestamp;
import java.util.Collection;
Expand All @@ -24,6 +26,7 @@ public class KruizeNotificationCollectionRegistry {
private String experiment_name;
private Timestamp interval_end_time;
private String container_name;
private static final Logger LOGGER = LoggerFactory.getLogger(KruizeNotificationCollectionRegistry.class);

/**
* Constructor to initialize KruizeNotificationCollectionRegistry with experiment name, interval end time, and container name.
Expand Down Expand Up @@ -78,7 +81,10 @@ public void createCounterTag(String level, String term, String model, Collection
for (RecommendationNotification recommendationNotification : recommendationNotificationList) {
Tags additionalTags = Tags.empty();
if (("|" + KruizeDeploymentInfo.log_recommendation_metrics_level + "|").contains("|" + recommendationNotification.getType() + "|") == true) {
additionalTags = additionalTags.and(KruizeConstants.KRUIZE_RECOMMENDATION_METRICS.TAG_NAME, String.format(KruizeConstants.KRUIZE_RECOMMENDATION_METRICS.notification_format, this.experiment_name, this.container_name, KruizeConstants.DateFormats.simpleDateFormatForUTC.format(this.interval_end_time), level, term, model, String.valueOf(recommendationNotification.getCode()), recommendationNotification.getType(), recommendationNotification.getMessage()));
String notificationLog = String.format(KruizeConstants.KRUIZE_RECOMMENDATION_METRICS.notification_format_for_LOG, this.experiment_name, this.container_name, KruizeConstants.DateFormats.simpleDateFormatForUTC.format(this.interval_end_time), level, term, model, String.valueOf(recommendationNotification.getCode()), recommendationNotification.getType(), recommendationNotification.getMessage());
String metricEntry = String.format(KruizeConstants.KRUIZE_RECOMMENDATION_METRICS.notification_format_for_METRICS, term, model, recommendationNotification.getType());
LOGGER.info(notificationLog);
additionalTags = additionalTags.and(KruizeConstants.KRUIZE_RECOMMENDATION_METRICS.TAG_NAME,metricEntry); // A metric entry with only three tags, which are unlikely to have many unique values, will therefore help reduce cardinality.
Counter counterNotifications = MetricsConfig.meterRegistry().find(KruizeConstants.KRUIZE_RECOMMENDATION_METRICS.METRIC_NAME).tags(additionalTags).counter();
if (counterNotifications == null) {
counterNotifications = MetricsConfig.timerBKruizeNotifications.tags(additionalTags).register(MetricsConfig.meterRegistry);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/autotune/utils/KruizeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,9 @@ public static final class KRUIZE_CONFIG_DEFAULT_VALUE {

public static final class KRUIZE_RECOMMENDATION_METRICS {
public static final String METRIC_NAME = "KruizeRecommendationsNotification";
public static final String TAG_NAME = "experiment_details";
public static final String notification_format = "%s|%s|%s|%s|%s|%s|%s|%s|%s"; //experiment_name,container_name,endtime,level,termname,modelname,code,type,message
public static final String TAG_NAME = "recommendations_notifications";
public static final String notification_format_for_LOG = "%s|%s|%s|%s|%s|%s|%s|%s|%s"; //experiment_name,container_name,endtime,level,termname,modelname,code,type,message
public static final String notification_format_for_METRICS = "%s|%s|%s"; //termname,modelname,type

}
}

0 comments on commit 17b23ba

Please sign in to comment.