Skip to content

Commit

Permalink
[FLINK-20533][datadog] Encapsulate metric meta data
Browse files Browse the repository at this point in the history
This allows us to use the 'MetricMetaData' container for histograms later on, which will not directly extend 'DMetric'.
  • Loading branch information
zentol committed Dec 15, 2020
1 parent ea317c2 commit 38e424f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DCounter extends DMetric {
private long currentReportCount = 0;

public DCounter(Counter c, String metricName, String host, List<String> tags, Clock clock) {
super(MetricType.count, metricName, host, tags, clock);
super(new MetricMetaData(MetricType.count, metricName, host, tags, clock));
counter = c;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DGauge extends DMetric {
private final Gauge<Number> gauge;

public DGauge(Gauge<Number> g, String metricName, String host, List<String> tags, Clock clock) {
super(MetricType.gauge, metricName, host, tags, clock);
super(new MetricMetaData(MetricType.gauge, metricName, host, tags, clock));
gauge = g;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DMeter extends DMetric {
private final Meter meter;

public DMeter(Meter m, String metricName, String host, List<String> tags, Clock clock) {
super(MetricType.gauge, metricName, host, tags, clock);
super(new MetricMetaData(MetricType.gauge, metricName, host, tags, clock));
meter = m;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,37 @@ public abstract class DMetric {
@VisibleForTesting
static final String FIELD_NAME_POINTS = "points";

private final String metricName;
private final MetricType type;
private final String host;
private final List<String> tags;
private final Clock clock;

public DMetric(MetricType metricType, String metricName, String host, List<String> tags, Clock clock) {
this.type = metricType;
this.metricName = metricName;
this.host = host;
this.tags = tags;
this.clock = clock;
private final MetricMetaData metaData;

public DMetric(MetricMetaData metaData) {
this.metaData = metaData;
}

@JsonGetter(FIELD_NAME_TYPE)
public MetricType getType() {
return type;
return metaData.getType();
}

@JsonGetter(FIELD_NAME_METRIC)
public String getMetricName() {
return metricName;
return metaData.getMetricName();
}

@JsonGetter(FIELD_NAME_HOST)
public String getHost() {
return host;
return metaData.getHost();
}

@JsonGetter(FIELD_NAME_TAGS)
public List<String> getTags() {
return tags;
return metaData.getTags();
}

@JsonGetter(FIELD_NAME_POINTS)
public List<List<Number>> getPoints() {
// One single data point
List<Number> point = new ArrayList<>();
point.add(clock.getUnixEpochTimestamp());
point.add(metaData.getClock().getUnixEpochTimestamp());
point.add(getMetricValue());

List<List<Number>> points = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.flink.metrics.datadog;

import java.util.List;

/**
* All metadata associated with a given metric.
*/
public final class MetricMetaData {

private final String metricName;
private final MetricType type;
private final String host;
private final List<String> tags;
private final Clock clock;

public MetricMetaData(MetricType metricType, String metricName, String host, List<String> tags, Clock clock) {
this.type = metricType;
this.metricName = metricName;
this.host = host;
this.tags = tags;
this.clock = clock;
}

public MetricType getType() {
return type;
}

public String getMetricName() {
return metricName;
}

public String getHost() {
return host;
}

public List<String> getTags() {
return tags;
}

public Clock getClock() {
return clock;
}
}

0 comments on commit 38e424f

Please sign in to comment.