Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

Implements metrics and metricdefinitions API #396

Closed
wants to merge 3 commits into from

Conversation

Copy link
Member

@nacx nacx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @danielestevez!

* @see <a href="https://docs.microsoft.com/en-us/rest/api/monitor/metricdefinitions">docs</a>
*/
@Delegate
MetricDefinitionsApi getMetricsDefinitionsApi(@PathParam("resourceid") String resourceid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two API classes have just one method. Worth having just one Metrics API that exposes the metrics and the definitions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my original idea but they're two different APIs in Azure and therefore deal with different entities and api-versions so i thought it'd be more maintainable if we'd keep it that way

@SerializedNames({ "data", "id", "name", "type", "unit" })
public static Metric create(final List<MetricData> data, final String id, final MetricName name, final String type,
final String unit) {
return new AutoValue_Metric(data, id, name, type, unit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforce immutable and non-nullable lists. If this is a read-only object, not something users will build and send to ARM in a request, then avoid having nullable collections (the typical tags field of an object is a counter-example as we need to send it as null, so we enforce immutability but not its presence):

new AutoValue_Metric(data == null ? ImmutableList.of() : ImmutableList.copyOf(data), id, name, type, unit);

Apply this pattern to all lists in the new model classes.

* The average value in the time range
*/
@Nullable
public abstract String total();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a String? Can we better make this a Double/Long? The same applies to all other numeric value fields.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a String according to Azure documentation but yes, i think we could get them as Double/Long. I'll test this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we could get Double for all fields but i still think we should return a String as Azure API does. If we force Double for let's say "total" this could be ok for metrics in bytes (as Network In) but would make no sense for metrics with no decimals (like Disk Read Operations/Sec that is a smaller count that could be even Int)

Since jclouds will not do any calculations with these values i think we should return them as they are and let the user decide how to parse them.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think a Number makes more sense. Having a number with .0 decimal is not a big deal, as you can still do arithmetic operations, etc, normally. Letting the users how to parse them propagates unnecessary complexity to them.


public abstract String unit();

public abstract String primaryAggregationType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a set of fixed values? Can we codify them in an enum?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Will change to enum: None, Average, Count, Total, Minimum, Maximum seem to be the only possible values

public abstract class MetricDefinition {

@Nullable
public abstract String resourceid();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use camel case.

final Boolean isDimensionRequired, final String unit, final String primaryAggregationType,
List<MetricAvailability> metricAvailabilities, final String id) {
return new AutoValue_MetricDefinition(resourceid, name, isDimensionRequired, unit, primaryAggregationType,
metricAvailabilities, id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about collection immutability.

}

@AutoValue
public abstract static class MetricName {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already defined in the Metric class. Better extract it to a top level type.

try {
node = getOnlyElement(view.getComputeService().createNodesInGroup(group, 1, resourceGroup(group)));
} catch (RunNodesException e) {
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fail the test instead of silently printing the error to the stdout?

try {
node = getOnlyElement(view.getComputeService().createNodesInGroup(group, 1, resourceGroup(group)));
} catch (RunNodesException e) {
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment

@nacx
Copy link
Member

nacx commented Jun 28, 2017

Squashed and pushed to master and 2.0.x.
I also changed the metrics mock test so it uses the date service to parse dates (see dffc2bb). Otherwise, there are locale-dependent issues when parsing dates and the results were non-deterministic.

@nacx nacx closed this Jun 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants