Skip to content

Commit

Permalink
Issue Netflix#38 Remove @monitorid. This is the main work, I still ne…
Browse files Browse the repository at this point in the history
…ed to verify some changes and do some testing.
  • Loading branch information
gorzell committed Apr 12, 2012
1 parent 76f1c5d commit 04da626
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void main(String[] args) throws Exception {
tags.add(InjectableTag.HOSTNAME);
tags.add(InjectableTag.IP);

BasicExample example = new BasicExample("test", tags);
BasicExample example = new BasicExample(tags);

DefaultMonitorRegistry.getInstance().registerObject(example);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class AnnotatedAttribute {

/** Creates a new instance. */
public AnnotatedAttribute(Object obj, Monitor anno, AccessibleObject attr) {
this(obj, anno, attr, BasicTagList.copyOf(anno.tags()));
this(obj, anno, attr, BasicTagList.EMPTY);
}

/** Creates a new instance. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,17 @@
public final class AnnotatedObject {

private final Object object;
private final String id;
private final TagList tags;
private final List<AnnotatedAttribute> attrs;

public AnnotatedObject(Object obj) throws Exception {
object = Preconditions.checkNotNull(obj);

String className = obj.getClass().getCanonicalName();
id = AnnotationUtils.getMonitorId(obj);

List<Tag> commonTags = Lists.newArrayList();
commonTags.add(new BasicTag(CLASS_NAME.getKeyName(), className));
if (id != null) {
commonTags.add(new BasicTag(MONITOR_ID.getKeyName(), id));
}

tags = BasicTagList.concat(
AnnotationUtils.getMonitorTags(obj),
new BasicTagList(commonTags));
Expand All @@ -73,11 +69,6 @@ public Object getObject() {
return object;
}

/** Returns the id from the {@link MonitorId} annotation. */
public String getId() {
return id;
}

/** Returns the tags from the {@link MonitorTags} annotation. */
public TagList getTags() {
return tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ public final class AnnotationUtils {
private AnnotationUtils() {
}

/**
* Return the value of the field/method annotated with {@link MonitorId}.
*/
public static String getMonitorId(Object obj) throws Exception {
List<AccessibleObject> fields =
getAnnotatedFields(MonitorId.class, obj, 1);
return fields.isEmpty() ? null : (String) getValue(obj, fields.get(0));
}

/**
* Return the value of the field/method annotated with
* {@link MonitorTags}.
Expand Down Expand Up @@ -73,13 +64,6 @@ public static List<AnnotatedAttribute> getMonitoredAttributes(Object obj) {

/** Check that the object conforms to annotation requirements. */
public static void validate(Object obj) {
try {
getMonitorId(obj);
} catch (Exception e) {
throw new IllegalArgumentException(
"invalid MonitorId annotation on object " + obj, e);
}

try {
getMonitorTags(obj);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.netflix.servo.tag.TagList;
import com.netflix.servo.annotations.DataSourceType;
import com.netflix.servo.annotations.Monitor;
import com.netflix.servo.annotations.MonitorId;
import com.netflix.servo.annotations.MonitorTags;

import java.util.ArrayList;
Expand All @@ -46,8 +45,6 @@ public class BasicExample {
description = "Sample gauge monitor")
private long sampleGuage = 0;



@MonitorTags
public final TagList tags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public MonitoredResource(String domain, AnnotatedObject obj) {
object = Preconditions.checkNotNull(obj, "object cannot be null");

String className = object.getClassName();
String id = object.getId();
name = createObjectName(domain, className, id, "value");
name = createObjectName(domain, className, "value");

ImmutableMap.Builder<String,MonitoredAttribute> builder =
ImmutableMap.builder();
Expand All @@ -89,7 +88,7 @@ public MonitoredResource(String domain, AnnotatedObject obj) {
null); // notifications

ObjectName metadataName =
createObjectName(domain, className, id, "metadata");
createObjectName(domain, className, "metadata");
MBeanInfo metadataInfo = new MBeanInfo(
className,
"MonitoredResource Metdata MBean",
Expand All @@ -101,14 +100,12 @@ public MonitoredResource(String domain, AnnotatedObject obj) {
}

private ObjectName createObjectName(
String domain, String className, String id, String field) {
String domain, String className, String field) {
StringBuilder buf = new StringBuilder();
buf.append((domain == null) ? getClass().getCanonicalName() : domain)
.append(":class=")
.append(className);
if (id != null) {
buf.append(",instance=").append(id);
}

buf.append(",field=").append(field);

String name = buf.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.netflix.servo.Metric;
import com.netflix.servo.annotations.DataSourceType;
import com.netflix.servo.annotations.Monitor;
import com.netflix.servo.annotations.MonitorId;
import com.netflix.servo.annotations.MonitorTags;
import com.netflix.servo.tag.*;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -34,7 +36,9 @@
* and number of failures.
*/
public abstract class BaseMetricObserver implements MetricObserver {
@MonitorId
@MonitorTags
private final TagList tags;

private final String name;

@Monitor(name="UpdateCount", type= DataSourceType.COUNTER,
Expand All @@ -48,6 +52,7 @@ public abstract class BaseMetricObserver implements MetricObserver {
/** Creates a new instance with a given name. */
public BaseMetricObserver(String name) {
this.name = Preconditions.checkNotNull(name);
this.tags = new BasicTagList(ImmutableSet.<Tag>of(new BasicTag(StandardTagKeys.MONITOR_ID.getKeyName(), name)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ private void getMetrics(
MetricFilter filter,
AnnotatedObject obj)
throws Exception {
String classId = obj.getId();
LOGGER.debug("retrieving metrics from class {} id {}",
obj.getClassName(), classId);

List<AnnotatedAttribute> attrs = obj.getAttributes();
for (AnnotatedAttribute attr : attrs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.netflix.servo.tag.TagList;
import com.netflix.servo.annotations.DataSourceType;
import com.netflix.servo.annotations.Monitor;
import com.netflix.servo.annotations.MonitorId;
import com.netflix.servo.annotations.MonitorTags;

import java.util.concurrent.atomic.AtomicLong;
Expand All @@ -35,7 +34,6 @@
*/
public final class BasicCounter {

@MonitorId
private final String name;

@MonitorTags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.netflix.servo.tag.Tag;
import com.netflix.servo.annotations.DataSourceType;
import com.netflix.servo.annotations.Monitor;
import com.netflix.servo.annotations.MonitorId;
import com.netflix.servo.annotations.MonitorTags;

import java.util.ArrayList;
Expand All @@ -38,13 +37,9 @@
public class TestMonitor {

@Monitor(name="testCounter", type = DataSourceType.COUNTER,
description = "Monitor for doing testing", tags = {
"tag1=foo", "tag2=bar"})
description = "Monitor for doing testing")
public final AtomicInteger counter = new AtomicInteger(0);

@MonitorId
public final String name = "testMonitor";

@MonitorTags
public final List<Tag> tagList = new ArrayList<Tag>(10);

Expand Down

0 comments on commit 04da626

Please sign in to comment.