Commit 5fb36b70 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Parse three new lines in snowflake statistics.

Implements #32665.
parent 067add63
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
# Changes in version 2.?.? - 2019-1?-??
# Changes in version 2.10.0 - 2019-1?-??

 * Medium changes
   - Parse three newly added lines in snowflake statistics files.

 * Minor changes
   - Fix a NullPointerException when parsing an invalid crypto block
+30 −0
Original line number Diff line number Diff line
@@ -51,6 +51,36 @@ public interface SnowflakeStats extends Descriptor {
   */
  Optional<Long> snowflakeIpsTotal();

  /**
   * Return a count of the total number of unique IP addresses of snowflake
   * proxies of type "standalone" that have polled.
   *
   * @return Count of the total number of unique IP addresses of snowflake
   *     proxies of type "standalone" that have polled.
   * @since 2.10.0
   */
  Optional<Long> snowflakeIpsStandalone();

  /**
   * Return a count of the total number of unique IP addresses of snowflake
   * proxies of type "badge" that have polled.
   *
   * @return Count of the total number of unique IP addresses of snowflake
   *     proxies of type "badge" that have polled.
   * @since 2.10.0
   */
  Optional<Long> snowflakeIpsBadge();

  /**
   * Return a count of the total number of unique IP addresses of snowflake
   * proxies of type "webext" that have polled.
   *
   * @return Count of the total number of unique IP addresses of snowflake
   *     proxies of type "webext" that have polled.
   * @since 2.10.0
   */
  Optional<Long> snowflakeIpsWebext();

  /**
   * Return a count of the number of times a proxy has polled but received no
   * client offer, rounded up to the nearest multiple of 8.
+3 −0
Original line number Diff line number Diff line
@@ -139,7 +139,10 @@ public enum Key {
  SIGNING_KEY("signing-key"),
  SNOWFLAKE_IDLE_COUNT("snowflake-idle-count"),
  SNOWFLAKE_IPS("snowflake-ips"),
  SNOWFLAKE_IPS_BADGE("snowflake-ips-badge"),
  SNOWFLAKE_IPS_STANDALONE("snowflake-ips-standalone"),
  SNOWFLAKE_IPS_TOTAL("snowflake-ips-total"),
  SNOWFLAKE_IPS_WEBEXT("snowflake-ips-webext"),
  SNOWFLAKE_STATS_END("snowflake-stats-end"),
  TRANSPORT("transport"),
  TUNNELLED_DIR_SERVER("tunnelled-dir-server"),
+49 −2
Original line number Diff line number Diff line
@@ -20,8 +20,10 @@ public class SnowflakeStatsImpl extends DescriptorImpl
    implements SnowflakeStats {

  private static final Set<Key> atMostOnce = EnumSet.of(
      Key.SNOWFLAKE_IPS, Key.SNOWFLAKE_IPS_TOTAL, Key.SNOWFLAKE_IDLE_COUNT,
      Key.CLIENT_DENIED_COUNT, Key.CLIENT_SNOWFLAKE_MATCH_COUNT);
      Key.SNOWFLAKE_IPS, Key.SNOWFLAKE_IPS_TOTAL, Key.SNOWFLAKE_IPS_STANDALONE,
      Key.SNOWFLAKE_IPS_BADGE, Key.SNOWFLAKE_IPS_WEBEXT,
      Key.SNOWFLAKE_IDLE_COUNT, Key.CLIENT_DENIED_COUNT,
      Key.CLIENT_SNOWFLAKE_MATCH_COUNT);

  private static final Set<Key> exactlyOnce = EnumSet.of(
      Key.SNOWFLAKE_STATS_END);
@@ -61,6 +63,15 @@ public class SnowflakeStatsImpl extends DescriptorImpl
        case SNOWFLAKE_IPS_TOTAL:
          this.parseSnowflakeIpsTotal(line, parts);
          break;
        case SNOWFLAKE_IPS_STANDALONE:
          this.parseSnowflakeIpsStandalone(line, parts);
          break;
        case SNOWFLAKE_IPS_BADGE:
          this.parseSnowflakeIpsBadge(line, parts);
          break;
        case SNOWFLAKE_IPS_WEBEXT:
          this.parseSnowflakeIpsWebext(line, parts);
          break;
        case SNOWFLAKE_IDLE_COUNT:
          this.parseSnowflakeIdleCount(line, parts);
          break;
@@ -104,6 +115,21 @@ public class SnowflakeStatsImpl extends DescriptorImpl
    this.snowflakeIpsTotal = ParseHelper.parseLong(line, parts, 1);
  }

  private void parseSnowflakeIpsStandalone(String line, String[] parts)
      throws DescriptorParseException {
    this.snowflakeIpsStandalone = ParseHelper.parseLong(line, parts, 1);
  }

  private void parseSnowflakeIpsBadge(String line, String[] parts)
      throws DescriptorParseException {
    this.snowflakeIpsBadge = ParseHelper.parseLong(line, parts, 1);
  }

  private void parseSnowflakeIpsWebext(String line, String[] parts)
      throws DescriptorParseException {
    this.snowflakeIpsWebext = ParseHelper.parseLong(line, parts, 1);
  }

  private void parseSnowflakeIdleCount(String line, String[] parts)
      throws DescriptorParseException {
    this.snowflakeIdleCount = ParseHelper.parseLong(line, parts, 1);
@@ -147,6 +173,27 @@ public class SnowflakeStatsImpl extends DescriptorImpl
    return Optional.ofNullable(this.snowflakeIpsTotal);
  }

  private Long snowflakeIpsStandalone;

  @Override
  public Optional<Long> snowflakeIpsStandalone() {
    return Optional.ofNullable(this.snowflakeIpsStandalone);
  }

  private Long snowflakeIpsBadge;

  @Override
  public Optional<Long> snowflakeIpsBadge() {
    return Optional.ofNullable(this.snowflakeIpsBadge);
  }

  private Long snowflakeIpsWebext;

  @Override
  public Optional<Long> snowflakeIpsWebext() {
    return Optional.ofNullable(this.snowflakeIpsWebext);
  }

  private Long snowflakeIdleCount;

  @Override
+12 −0
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@ public class SnowflakeStatsImplTest {
          + "PK=4,ID=9,IR=7,JO=2,CR=2,US=265,DE=92,LV=1,MY=8,AR=5,NZ=10,BG=2,"
          + "UY=1,TW=5,SI=3,LU=2,GE=2,BN=1,JP=15,ES=9,SG=7,EC=1",
      "snowflake-ips-total 937",
      "snowflake-ips-standalone 3",
      "snowflake-ips-badge 0",
      "snowflake-ips-webext 4118",
      "snowflake-idle-count 660976",
      "client-denied-count 0",
      "client-snowflake-match-count 864" };
@@ -51,6 +54,12 @@ public class SnowflakeStatsImplTest {
    assertEquals(68, snowflakeStats.snowflakeIps().get().size());
    assertTrue(snowflakeStats.snowflakeIpsTotal().isPresent());
    assertEquals((Long) 937L, snowflakeStats.snowflakeIpsTotal().get());
    assertTrue(snowflakeStats.snowflakeIpsStandalone().isPresent());
    assertEquals((Long) 3L, snowflakeStats.snowflakeIpsStandalone().get());
    assertTrue(snowflakeStats.snowflakeIpsBadge().isPresent());
    assertEquals((Long) 0L, snowflakeStats.snowflakeIpsBadge().get());
    assertTrue(snowflakeStats.snowflakeIpsWebext().isPresent());
    assertEquals((Long) 4118L, snowflakeStats.snowflakeIpsWebext().get());
    assertTrue(snowflakeStats.snowflakeIdleCount().isPresent());
    assertEquals((Long) 660976L, snowflakeStats.snowflakeIdleCount().get());
    assertTrue(snowflakeStats.clientDeniedCount().isPresent());
@@ -69,6 +78,9 @@ public class SnowflakeStatsImplTest {
        snowflakeStats.snowflakeStatsIntervalLength());
    assertFalse(snowflakeStats.snowflakeIps().isPresent());
    assertFalse(snowflakeStats.snowflakeIpsTotal().isPresent());
    assertFalse(snowflakeStats.snowflakeIpsStandalone().isPresent());
    assertFalse(snowflakeStats.snowflakeIpsBadge().isPresent());
    assertFalse(snowflakeStats.snowflakeIpsWebext().isPresent());
    assertFalse(snowflakeStats.snowflakeIdleCount().isPresent());
    assertFalse(snowflakeStats.clientDeniedCount().isPresent());
    assertFalse(snowflakeStats.clientSnowflakeMatchCount().isPresent());