Skip to content

Commit

Permalink
Fixes #983: log usage of unstable api
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Feb 15, 2018
1 parent 89a2c83 commit a1f03da
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.fabric8.kubernetes.client.internal.VersionUsageUtils;
import io.fabric8.kubernetes.client.utils.Serialization;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
Expand Down Expand Up @@ -373,6 +374,7 @@ protected <T> T handleResponse(OkHttpClient client, Request.Builder requestBuild
* @throws IOException
*/
protected <T> T handleResponse(OkHttpClient client, Request.Builder requestBuilder, Class<T> type, Map<String, String> parameters) throws ExecutionException, InterruptedException, KubernetesClientException, IOException {
VersionUsageUtils.log(this.resourceT, this.apiVersion);
Request request = requestBuilder.build();
Response response = client.newCall(request).execute();
try (ResponseBody body = response.body()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.fabric8.kubernetes.client.internal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ConcurrentHashMap;

/**
* Utility class to monitor alhpa/beta version usage and log.
*/
public final class VersionUsageUtils {

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

private static ConcurrentHashMap<String, Boolean> UNSTABLE_TYPES = new ConcurrentHashMap<>();

private static final boolean LOG_EACH_USAGE = false;

private VersionUsageUtils() {
}

public static void log(String type, String version) {
if (type == null || version == null) {
return;
}

if (isUnstable(version)) {
if (LOG_EACH_USAGE || UNSTABLE_TYPES.putIfAbsent(type + "-" + version, true) == null) {
alert(type, version);
}
}
}

private static boolean isUnstable(String version) {
String lowerCaseVersion = version.toLowerCase();
return lowerCaseVersion.contains("beta") || lowerCaseVersion.contains("alpha");
}

private static void alert(String type, String version) {
LOG.warn("The client is using resource type '{}' with unstable version '{}'", type, version);
}

}

0 comments on commit a1f03da

Please sign in to comment.