Skip to content

Commit

Permalink
Merge pull request #80 from gigya/develop
Browse files Browse the repository at this point in the history
merge from develop to master: Microdot 1.5.1, ServiceContract 2.4.14
  • Loading branch information
bronsh authored Sep 4, 2017
2 parents 9bb6cd1 + c378916 commit a6031b3
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 58 deletions.
7 changes: 5 additions & 2 deletions Gigya.Microdot.Orleans.Hosting/MetricsStatisticsPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Gigya.Microdot.Orleans.Hosting
internal class MetricsStatisticsPublisher : IConfigurableStatisticsPublisher , IConfigurableSiloMetricsDataPublisher, IConfigurableClientMetricsDataPublisher , IProvider
{
private readonly ConcurrentDictionary<string, double> latestMetricValues = new ConcurrentDictionary<string, double>();
private long latestRequestQueueLength = 0;

/// <summary>Contains a set of gauges whose lambda getter methods fetch their values from <see cref="latestMetricValues"/></summary>
private readonly MetricsContext context = Metric.Context("Silo");
Expand Down Expand Up @@ -82,6 +83,8 @@ private void PublishMetrics(IEnumerable<ICounter> statsCounters)
}
}
}

context.Gauge("Request queue length", ()=>latestRequestQueueLength, Unit.Items);
}

public Task Init(bool isSilo, string storageConnectionString, string deploymentId, string address, string siloName, string hostName)
Expand All @@ -99,9 +102,9 @@ public Task Init(string deploymentId, string storageConnectionString, SiloAddres
return TaskDone.Done;
}

public Task ReportMetrics(ISiloPerformanceMetrics metricsData)
public async Task ReportMetrics(ISiloPerformanceMetrics metricsData)
{
return TaskDone.Done;
latestRequestQueueLength = metricsData.RequestQueueLength;
}

void IConfigurableSiloMetricsDataPublisher.AddConfiguration(string deploymentId, bool isSilo, string siloName, SiloAddress address, IPEndPoint gateway, string hostName)
Expand Down
2 changes: 1 addition & 1 deletion Gigya.Microdot.ServiceDiscovery/ConsulDiscoverySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public override Exception AllEndpointsUnreachable(EndPointsResult endPointsResul
else if (endPointsResult.Error != null)
return new EnvironmentException("Error calling Consul. See tags for details.", unencrypted: tags);
else if (endPointsResult.IsQueryDefined == false)
return new EnvironmentException("Query not exists on Consul. See tags for details.", unencrypted: tags);
return new EnvironmentException("Query doesn't exists on Consul. See tags for details.", unencrypted: tags);
else
return new EnvironmentException("No endpoint were specified in Consul for the requested service.", unencrypted: tags);
}
Expand Down
6 changes: 3 additions & 3 deletions Gigya.Microdot.SharedLogic/Events/EventFieldFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ static string SerializeFieldValue(TypeCode tc, object fieldValue)
case TypeCode.String:
return fieldValue.ToString();
case TypeCode.Single:
return Math.Round((float)fieldValue, 4).ToString(CultureInfo.InvariantCulture);
return Math.Round((float)fieldValue, 3).ToString(CultureInfo.InvariantCulture);
case TypeCode.Double:
return Math.Round((double)fieldValue, 4).ToString(CultureInfo.InvariantCulture);
return Math.Round((double)fieldValue, 3).ToString(CultureInfo.InvariantCulture);
case TypeCode.Decimal:
return Math.Round((decimal)fieldValue, 4).ToString(CultureInfo.InvariantCulture);
return Math.Round((decimal)fieldValue, 3).ToString(CultureInfo.InvariantCulture);
case TypeCode.DateTime:
return ((DateTime)fieldValue).ToUniversalTime().ToString("o", CultureInfo.InvariantCulture);
case TypeCode.Boolean:
Expand Down
48 changes: 29 additions & 19 deletions Gigya.ServiceContract/HttpService/ServiceSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ public class ServiceSchema
{
public InterfaceSchema[] Interfaces { get; set; }

public ServiceSchema() {}
public ServiceSchema() { }

public ServiceSchema(Type[] interfaces)
{
Interfaces = interfaces.Select(_ => new InterfaceSchema(_)).ToArray();
}

}


public class InterfaceSchema
{
public string Name { get; set; }
Expand All @@ -60,7 +58,7 @@ public class InterfaceSchema

public MethodSchema[] Methods { get; set; }

public InterfaceSchema() {}
public InterfaceSchema() { }

public InterfaceSchema(Type iface)
{
Expand All @@ -71,7 +69,7 @@ public InterfaceSchema(Type iface)
Methods = iface.GetMethods().Select(m => new MethodSchema(m)).ToArray();
Attributes = iface
.GetCustomAttributes()
.Where(a => a.GetType().Namespace?.StartsWith("System.Diagnostics") == false)
.Where(AttributeSchema.FilterAttributes)
.Select(a => new AttributeSchema(a))
.ToArray();
}
Expand All @@ -98,7 +96,13 @@ public MethodSchema(MethodInfo info)
{
Name = info.Name;

if (info.ReturnType.IsGenericType && info.ReturnType.GetGenericTypeDefinition()==typeof(Task<>))

if (info.ReturnType == typeof(Task))
{
Response = null;

}
else if (info.ReturnType.IsGenericType && info.ReturnType.GetGenericTypeDefinition() == typeof(Task<>))
{
var resultType = info.ReturnType.GetGenericArguments().Single();
IsRevocable = typeof(IRevocable).IsAssignableFrom(resultType);
Expand All @@ -109,11 +113,11 @@ public MethodSchema(MethodInfo info)
Response = new TypeSchema(info.ReturnType, info.ReturnType.GetCustomAttributes());
}

ResponseType = Response.TypeName;
ResponseType = Response?.TypeName;
Parameters = info.GetParameters().Select(p => new ParameterSchema(p)).ToArray();
Attributes = info
.GetCustomAttributes()
.Where(a => a.GetType().Namespace?.StartsWith("System.Diagnostics") == false)
.Where(AttributeSchema.FilterAttributes)
.Select(a => new AttributeSchema(a))
.ToArray();
}
Expand All @@ -135,9 +139,9 @@ public SimpleTypeSchema(Type type, IEnumerable<Attribute> attributes)
Type = type;
TypeName = type.AssemblyQualifiedName;
Attributes = attributes
.Where(a => a.GetType().Namespace?.StartsWith("System.Diagnostics") == false)
.Select(a => new AttributeSchema(a))
.ToArray();
.Where(AttributeSchema.FilterAttributes)
.Select(a => new AttributeSchema(a))
.ToArray();
}

[OnDeserialized]
Expand All @@ -151,16 +155,17 @@ private void OnDeserialized(StreamingContext context)
}
}

public class TypeSchema: SimpleTypeSchema
public class TypeSchema : SimpleTypeSchema
{
public FieldSchema[] Fields { get; set; }

public TypeSchema() { }

public TypeSchema(Type type, IEnumerable<Attribute> attributes): base(type, attributes)
public TypeSchema(Type type, IEnumerable<Attribute> attributes) : base(type, attributes)
{
if (IsCompositeType(type))
Fields = GetFields(type).ToArray();

}

private IEnumerable<FieldSchema> GetFields(Type type)
Expand All @@ -173,21 +178,22 @@ private IEnumerable<FieldSchema> GetFields(Type type)

private bool IsCompositeType(Type type)
{

return !type.IsValueType && !(type == typeof(string));
}
}

public class ParameterSchema: TypeSchema
public class ParameterSchema : TypeSchema
{
public string Name { get; set; }

public ParameterSchema() { }

public ParameterSchema(ParameterInfo param): this (param.Name, param.ParameterType, param.GetCustomAttributes())
public ParameterSchema(ParameterInfo param) : this(param.Name, param.ParameterType, param.GetCustomAttributes())
{
}

protected ParameterSchema(string name, Type type, IEnumerable<Attribute> attributes): base(type, attributes)
protected ParameterSchema(string name, Type type, IEnumerable<Attribute> attributes) : base(type, attributes)
{
Name = name;
}
Expand Down Expand Up @@ -220,8 +226,7 @@ public class AttributeSchema

public JObject Data { get; set; }


public AttributeSchema() {}
public AttributeSchema() { }

public AttributeSchema(Attribute attribute)
{
Expand All @@ -234,14 +239,19 @@ public AttributeSchema(Attribute attribute)
private void OnDeserialized(StreamingContext context)
{
try
{
{
Type t = Type.GetType(TypeName);

if (t != null)
Attribute = (Attribute)Data.ToObject(t);
}
catch { }
}

internal static bool FilterAttributes(Attribute a)
{
return a.GetType().Namespace?.StartsWith("System.Diagnostics") == false && a.GetType().Namespace?.StartsWith("System.Security") == false;
}
}

}
6 changes: 3 additions & 3 deletions Gigya.ServiceContract/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
[assembly: AssemblyTrademark("")]


[assembly: AssemblyInformationalVersion("2.4.13")]// if pre-release should be in the format of "2.4.11-pre01".
[assembly: AssemblyVersion("2.4.13")]
[assembly: AssemblyFileVersion("2.4.13")]
[assembly: AssemblyInformationalVersion("2.4.14")]// if pre-release should be in the format of "2.4.11-pre01".
[assembly: AssemblyVersion("2.4.14")]
[assembly: AssemblyFileVersion("2.4.14")]

[assembly: AssemblyDescription("")]

Expand Down
6 changes: 3 additions & 3 deletions SolutionVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
[assembly: AssemblyCopyright("© 2017 Gigya Inc.")]
[assembly: AssemblyDescription("Microdot Framework")]

[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyInformationalVersion("1.5.0.0")]
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]
[assembly: AssemblyInformationalVersion("1.5.1.0")]


// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="ServiceProxyTests\JsonExceptionSerializerTests.cs" />
<Compile Include="ServiceProxyTests\MetricsTests.cs" />
<Compile Include="ServiceProxyTests\NinjectTest.cs" />
<Compile Include="ServiceSchemaTests.cs" />
<Compile Include="SourceBlockShould.cs" />
<Compile Include="StringExtensionsTest.cs" />
<Compile Include="TagsExtractorTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;

using Gigya.Microdot.Orleans.Hosting;
Expand All @@ -12,6 +13,7 @@

using Orleans.Providers;
using Orleans.Runtime;
using Shouldly;

namespace Gigya.Microdot.UnitTests
{
Expand Down Expand Up @@ -62,20 +64,14 @@ public void ClosePublisherTest()
public void PublishEmptyListTest()
{
publisher.ReportStats(new List<ICounter>()).Wait();
GetMetricsData().AssertEquals(new MetricsDataEquatable
{
Gauges = new List<MetricDataEquatable>()
});
GetMetricsData().Gauges.ShouldNotBeNull();
}

[Test]
public void PublishNullTest()
{
publisher.ReportStats(null).Wait();
GetMetricsData().AssertEquals(new MetricsDataEquatable
{
Gauges = new List<MetricDataEquatable>()
});
GetMetricsData().Gauges.ShouldNotBeNull();
}

[Test]
Expand All @@ -89,10 +85,7 @@ public void LogOnlyCounterNotPublishedTest()

publisher.ReportStats(new List<ICounter> { counter }).Wait();

GetMetricsData().AssertEquals(new MetricsDataEquatable
{
Gauges = new List<MetricDataEquatable>()
});
GetGauge("LogOnlyCounter").ShouldBeNull();
}

[Test]
Expand All @@ -106,9 +99,7 @@ public void PublishNonDeltaCounterTest()

publisher.ReportStats(new List<ICounter> { counter }).Wait();

var mdata = GetMetricsRepresentation("NonDeltaCounter", 100);

GetMetricsData().AssertEquals(mdata);
GetGauge("NonDeltaCounter").Value.ShouldBe(100);
}
[Test]
public void UpdateNonDeltaCounterTest()
Expand All @@ -120,15 +111,13 @@ public void UpdateNonDeltaCounterTest()
counter.GetValueString().Returns("100");

publisher.ReportStats(new List<ICounter> { counter }).Wait();

var mdata = GetMetricsRepresentation("NonDeltaCounter", 100);
GetMetricsData().AssertEquals(mdata);

GetGauge("NonDeltaCounter").Value.ShouldBe(100);

counter.GetValueString().Returns("300");
publisher.ReportStats(new List<ICounter> { counter }).Wait();

mdata = GetMetricsRepresentation("NonDeltaCounter", 300);
GetMetricsData().AssertEquals(mdata);
GetGauge("NonDeltaCounter").Value.ShouldBe(300);
}

[Test]
Expand All @@ -142,9 +131,7 @@ public void PublishDeltaCounterTest()

publisher.ReportStats(new List<ICounter> { counter }).Wait();

var mdata = GetMetricsRepresentation("DeltaCounter", 100);

GetMetricsData().AssertEquals(mdata);
GetGauge("DeltaCounter").Value.ShouldBe(100);
}

[Test]
Expand All @@ -158,13 +145,11 @@ public void UpdateDeltaCounterTest()

publisher.ReportStats(new List<ICounter> { counter }).Wait();

var mdata = GetMetricsRepresentation("DeltaCounter", 100);
GetMetricsData().AssertEquals(mdata);
GetGauge("DeltaCounter").Value.ShouldBe(100);

publisher.ReportStats(new List<ICounter> { counter }).Wait();

mdata = GetMetricsRepresentation("DeltaCounter", 200);
GetMetricsData().AssertEquals(mdata);
GetGauge("DeltaCounter").Value.ShouldBe(200);
}

private static MetricsDataEquatable GetMetricsRepresentation(string counterName,long val)
Expand All @@ -185,6 +170,12 @@ private static MetricsData GetMetricsData()
Metric.Context("Silo")
.DataProvider.CurrentMetricsData;
}

private static GaugeValueSource GetGauge(string gaugeName)
{
return GetMetricsData().Gauges.FirstOrDefault(g => g.Name == gaugeName);
}

}

}
Loading

0 comments on commit a6031b3

Please sign in to comment.