Skip to content

Commit

Permalink
feat(stats): Adds Telemetry validator, which prints a new Info level …
Browse files Browse the repository at this point in the history
…message that will get printed during all hal config telemetry enable|disable and hal deploy apply invocations
  • Loading branch information
Travis Tomsu committed Dec 9, 2019
1 parent 6545631 commit 099960c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ private static void formatProblemSet(ProblemSet problemSet) {
List<String> options = problem.getOptions();

switch (severity) {
case INFO:
AnsiUi.info(message);
break;
case FATAL:
case ERROR:
AnsiUi.error(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void problemLocation(String message) {
AnsiParagraphBuilder builder =
new AnsiParagraphBuilder().setIndentFirstLine(false).setIndentWidth(2);

builder.addSnippet("Problems in ");
builder.addSnippet("Validation in ");

builder.addSnippet(message).addStyle(AnsiStyle.BOLD);

Expand All @@ -46,6 +46,20 @@ public static void problemLocation(String message) {
AnsiPrinter.err.println(builder.toString());
}

public static void info(String message) {
AnsiParagraphBuilder builder =
new AnsiParagraphBuilder().setIndentFirstLine(false).setIndentWidth(2);

builder
.addSnippet("- INFO ")
.setForegroundColor(AnsiForegroundColor.GREEN)
.addStyle(AnsiStyle.BOLD);

builder.addSnippet(message);

AnsiPrinter.out.println(builder.toString());
}

public static void warning(String message) {
AnsiParagraphBuilder builder =
new AnsiParagraphBuilder().setIndentFirstLine(false).setIndentWidth(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public String getNodeName() {
return "telemetry";
}

@ValidForSpinnakerVersion(
lowerBound = "1.18.0",
tooLowMessage = "Telemetry is not available prior to this release.")
private Boolean enabled = false;

private String endpoint = DEFAULT_TELEMETRY_ENDPOINT;
private String instanceId = new ULID().nextULID();
private String spinnakerVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public ProblemSet validateDeployment(String deploymentName) {
.withAnyProvider()
.withAnyAccount()
.setFeatures()
.setSecurity();
.setSecurity()
.setTelemetry();

if (storage.getPersistentStoreType() != null) {
filter.setPersistentStore(storage.getPersistentStoreType().getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.netflix.spinnaker.halyard.config.validate.v1;

import com.netflix.spinnaker.halyard.config.model.v1.node.Telemetry;
import com.netflix.spinnaker.halyard.config.model.v1.node.Validator;
import com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder;
import com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TelemetryValidator extends Validator<Telemetry> {

@Override
public void validate(ConfigProblemSetBuilder p, Telemetry t) {
StringBuilder msg = new StringBuilder();
msg.append("Telemetry is currently ");
if (t.getEnabled()) {
msg.append("ENABLED. Usage statistics are being collected—Thank you! ");
msg.append("These stats inform improvements to the product, and that helps the community. ");
msg.append("To disable, run `hal config telemetry disable`. ");
} else {
msg.append("DISABLED. Usage statistics are not being collected. ");
msg.append("Please consider enabling statistic collection. ");
msg.append("These stats inform improvements to the product, and that helps the community. ");
msg.append("To enable, run `hal config telemetry enable`. ");
}

msg.append("To learn more about what and how telemetry data is used, please see ");
msg.append("https://www.spinnaker.io/community/stats.");
p.addProblem(Severity.INFO, msg.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public enum Severity {
*/
NONE,

/** Indicates no problem at all, just information that should be shared with the user. */
INFO,

/**
* Indicates the deployment of Spinnaker is going against our preferred/recommended practices.
* For example: using an unauthenticated docker registry.
Expand Down

0 comments on commit 099960c

Please sign in to comment.