public static Points<BasicRollup> generateFakeRollupPoints() { Points<BasicRollup> points = new Points<BasicRollup>(); long baseTime = 1234567L; for (int count = 0; count < 5; count++) { final BasicRollup basicRollup = new BasicRollup(); basicRollup.setCount(count * 100); basicRollup.getAverage().setLongValue(count); Points.Point<BasicRollup> point = new Points.Point<BasicRollup>(baseTime + (count*1000), basicRollup); points.add(point); } return points; }
public static Points<SimpleNumber> generateFakeFullResPoints() { Points<SimpleNumber> points = new Points<SimpleNumber>(); long baseTime = 1234567L; for (int count = 0; count < 5; count++) { Points.Point<SimpleNumber> point = new Points.Point<SimpleNumber>(baseTime + (count*1000), new SimpleNumber((long) count)); points.add(point); } return points; }
public static Points<BluefloodGaugeRollup> generateFakeGaugeRollups() { Points<BluefloodGaugeRollup> points = new Points<BluefloodGaugeRollup>(); long startTime = 1234567L; for (int i = 0; i < 5; i++) { long timeNow = startTime + i*1000; Points.Point<BluefloodGaugeRollup> point = new Points.Point<BluefloodGaugeRollup>(timeNow, new BluefloodGaugeRollup() .withLatest(timeNow, i)); points.add(point); } return points; }
boolean hasAllZeroData(MetricData dataPoints) { boolean allZeroFlag = true; // Points should be of type BasicRollup. Will throw an exception if they are not. Map<Long, Points.Point<BasicRollup>> points = dataPoints.getData().getPoints(); for (Map.Entry<Long, Points.Point<BasicRollup>> entry : points.entrySet()) { BasicRollup basicRollup = entry.getValue().getData(); if((basicRollup.getMaxValue().isFloatingPoint() ? basicRollup.getMaxValue().toDouble() != 0.0 : basicRollup.getMaxValue().toLong() != 0) && (basicRollup.getMinValue().isFloatingPoint() ? basicRollup.getMinValue().toDouble() != 0.0 : basicRollup.getMinValue().toLong() != 0) && (basicRollup.getAverage().isFloatingPoint() ? basicRollup.getAverage().toDouble() != 0.0 : basicRollup.getAverage().toLong() != 0)) { allZeroFlag = false; break; } } return allZeroFlag; }
public static Collection<PreaggregatedMetric> convertGauges(String tenant, long timestamp, Collection<BluefloodGauge> gauges) { List<PreaggregatedMetric> list = new ArrayList<PreaggregatedMetric>(gauges.size()); for (BluefloodGauge gauge : gauges) { Locator locator = Locator.createLocatorFromPathComponents(tenant, gauge.getName().split(NAME_DELIMITER, -1)); Points<SimpleNumber> points = new Points<SimpleNumber>(); points.add(new Points.Point<SimpleNumber>(timestamp, new SimpleNumber(resolveNumber(gauge.getValue())))); try { Rollup rollup = BluefloodGaugeRollup.buildFromRawSamples(points); PreaggregatedMetric metric = new PreaggregatedMetric(timestamp, locator, DEFAULT_TTL, rollup); list.add(metric); } catch (IOException ex) { throw new IOError(ex); } } return list; }
public static Points<BluefloodTimerRollup> generateFakeTimerRollups() { Points<BluefloodTimerRollup> points = new Points<BluefloodTimerRollup>(); long startTime = 1234567L; for (int i = 0; i < 5; i++) { long timeNow = startTime + i*1000; BluefloodTimerRollup rollup = new BluefloodTimerRollup() .withAverage(i) .withCount(i) .withCountPS(i*0.1d) .withMaxValue(i) .withMinValue(i) .withSum(Double.valueOf(i+i)) .withVariance(i); rollup.setPercentile("50", i); rollup.setPercentile("99", i * 2 + 1); Points.Point<BluefloodTimerRollup> point = new Points.Point<BluefloodTimerRollup>(timeNow, rollup); points.add(point); } return points; } }
public static Points<BluefloodCounterRollup> generateFakeCounterRollupPoints() { Points<BluefloodCounterRollup> points = new Points<BluefloodCounterRollup>(); long startTime = 1234567L; for (int i = 0; i < 5; i++) { long timeNow = startTime + i*1000; Points.Point<BluefloodCounterRollup> point = new Points.Point<BluefloodCounterRollup>(timeNow, new BluefloodCounterRollup() .withCount(i + 1000) .withRate((double) i) .withSampleCount(i+1)); points.add(point); } return points; }
public static Collection<PreaggregatedMetric> convertSets(String tenant, long timestamp, Collection<BluefloodSet> sets) { List<PreaggregatedMetric> list = new ArrayList<PreaggregatedMetric>(sets.size()); for (BluefloodSet set : sets) { Locator locator = Locator.createLocatorFromPathComponents(tenant, set.getName().split(NAME_DELIMITER, -1)); BluefloodSetRollup rollup = new BluefloodSetRollup(); for (String value : set.getValues()) { rollup = rollup.withObject(value); } PreaggregatedMetric metric = new PreaggregatedMetric(timestamp, locator, DEFAULT_TTL, rollup); list.add(metric); } return list; }
public static Points<BluefloodSetRollup> generateFakeSetRollupPoints() { Points<BluefloodSetRollup> points = new Points<BluefloodSetRollup>(); long startTime = 1234567L; for (int i = 0; i < 5; i++) { long timeNow = startTime + i*1000; Points.Point<BluefloodSetRollup> point = new Points.Point<BluefloodSetRollup>(timeNow, new BluefloodSetRollup() .withObject(i) .withObject(i % 2) .withObject(i / 2)); points.add(point); } return points; }
@Override Object convertRollupToObject(Rollup rollup) throws UnsupportedOperationException { if (rollup instanceof BaseRollup) return ((BaseRollup) rollup).getCount(); else if (rollup instanceof BluefloodTimerRollup) return ((BluefloodTimerRollup) rollup).getCount(); else if (rollup instanceof BluefloodCounterRollup) return ((BluefloodCounterRollup) rollup).getSampleCount(); else if (rollup instanceof BluefloodSetRollup) return ((BluefloodSetRollup) rollup).getCount(); else // gauge. throw new UnsupportedOperationException( String.format("numPoints not supported for this type: %s", rollup.getClass().getSimpleName())); }
@Override Object convertRollupToObject(Rollup rollup) throws UnsupportedOperationException { if( rollup instanceof BasicRollup ) return ((BasicRollup) rollup).getSum(); else if (rollup instanceof BluefloodTimerRollup) return ((BluefloodTimerRollup) rollup).getSum(); else if (rollup instanceof BluefloodCounterRollup) return ((BluefloodCounterRollup) rollup).getCount(); else // every other type. throw new UnsupportedOperationException( String.format("sum not supported for this type: %s", rollup.getClass().getSimpleName())); }
@Override Object convertRollupToObject(Rollup rollup) throws UnsupportedOperationException { if (rollup instanceof BasicRollup) return ((BasicRollup) rollup).getAverage(); else if (rollup instanceof BluefloodTimerRollup) return ((BluefloodTimerRollup) rollup).getAverage(); else // counters, sets throw new UnsupportedOperationException( String.format("average not supported for this type: %s", rollup.getClass().getSimpleName())); }
@Override Object convertRollupToObject(Rollup rollup) throws UnsupportedOperationException { if (rollup instanceof BasicRollup) return ((BasicRollup) rollup).getMaxValue(); else if (rollup instanceof BluefloodTimerRollup) return ((BluefloodTimerRollup) rollup).getMaxValue(); else // counters, sets. throw new UnsupportedOperationException( String.format("min not supported for this type: %s", rollup.getClass().getSimpleName())); }
@Test public void testCreateSingleRequest_WithNullMetricName() throws IOException { final String TENANT_A = "12345"; Locator locator = Locator.createLocatorFromPathComponents(TENANT_A); assertEquals(0, Token.getTokens(locator).size()); }
protected static List<IMetric> createTestMetricsFromInterface(String tenantId) { IMetric metric; List<IMetric> metrics = new ArrayList<>(); BluefloodCounterRollup counter = new BluefloodCounterRollup(); List<Locator> locators = createComplexTestLocators(tenantId); for (Locator locator : locators) { metric = new PreaggregatedMetric(0, locator, new TimeValue(1, TimeUnit.DAYS), counter); metrics.add(metric); } return metrics; }
private String getUnit(Metric metric) { return metric.getUnit(); }
private RollupsQueryParams(long from, long to, Set<BasicRollupsOutputSerializer.MetricStat> stats) { if (from >= to) { throw new IllegalArgumentException("'from' timestamp has to be strictly less than 'to'."); } this.stats = stats; this.range = new Range(from, to); this.points = 0; this.resolution = Resolution.FULL; }
private void forceTTLsIfConfigured(List<Metric> containerMetrics) { ConfigTtlProvider configTtlProvider = ConfigTtlProvider.getInstance(); if(configTtlProvider.areTTLsForced()) { for(Metric m : containerMetrics) { m.setTtl(configTtlProvider.getConfigTTLForIngestion()); } } } }