Skip to content

Commit 76f82b6

Browse files
committed
Things to allow cross domain working
1 parent 8276d3e commit 76f82b6

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

Tether.Plugins/Metric.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,29 @@
66

77
namespace Tether.Plugins
88
{
9+
[Serializable]
910
public class Metric
1011
{
1112
public Metric()
1213
{
1314
Timestamp = DateTime.UtcNow;
1415
}
1516

16-
public Metric(string name, DateTime timestamp, float value, MetricType type, string hostname,
17+
public Metric(string name, DateTime timestamp, float? value, MetricType type, string hostname,
1718
Dictionary<string, string> tags)
1819
{
1920
Name = name ?? throw new ArgumentNullException(nameof(name));
2021
Timestamp = timestamp;
21-
Value = value;
22+
Value = value ?? 0;
2223
Type = type;
2324
Hostname = hostname ?? throw new ArgumentNullException(nameof(hostname));
2425
Tags = tags;
2526
}
2627

27-
public Metric(string name, float value, MetricType type = MetricType.Gauge, Dictionary<string, string> tags=null)
28+
public Metric(string name, float? value, MetricType type = MetricType.Gauge, Dictionary<string, string> tags=null)
2829
{
2930
Name = name ?? throw new ArgumentNullException(nameof(name));
30-
Value = value;
31+
Value = value ?? 0;
3132
Type = type;
3233
Tags = tags;
3334
Hostname = Environment.MachineName;

Tether/InstanceProxy.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.Dynamic;
5+
using System.IO;
46
using System.Linq;
57
using System.Management;
68
using System.Reflection;
79
using System.Threading;
810
using Newtonsoft.Json;
11+
using Newtonsoft.Json.Converters;
912
using Tether.Plugins;
1013
using Utilities.DataTypes.ExtensionMethods;
1114

@@ -39,6 +42,12 @@ public InstanceProxy()
3942
longRunningResults = new List<LongRunningResult>();
4043
}
4144

45+
public void AddSettings(string name, string values)
46+
{
47+
var value = JsonConvert.DeserializeObject<ExpandoObject>(values, new ExpandoObjectConverter()) as dynamic;
48+
PluginSettings.Add(name, value);
49+
}
50+
4251
public Dictionary<string, string> GetLongRunningChecks()
4352
{
4453
Dictionary<string, string> results = new Dictionary<string, string>();
@@ -117,7 +126,7 @@ public List<Metric> PerformCheck(string checkName)
117126

118127
if (check is IRequireConfigurationData)
119128
{
120-
if (PluginSettings[check.GetType().FullName] != null)
129+
if ( PluginSettings.ContainsKey(check.GetType().FullName))
121130
{
122131
(check as IRequireConfigurationData).LoadConfigurationData(PluginSettings[check.GetType().FullName]);
123132
}

Tether/Service.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Dynamic;
55
using System.IO;
66
using System.Linq;
7+
using System.Runtime.Remoting;
78
using System.Threading;
89
using System.Threading.Tasks;
910
using System.Timers;
@@ -215,7 +216,7 @@ private void DetectPlugins()
215216
{
216217
var def = AssemblyDefinition.ReadAssembly(info.FullName);
217218

218-
var it = def.MainModule.Types.Where(e => e.Interfaces.Any(r => (r.FullName == typeof(ICheck).FullName)) || (e.Interfaces.Any(r => r.FullName == typeof(ILongRunningMetricProvider).FullName))).ToList();
219+
var it = def.MainModule.Types.Where(e => e.Interfaces.Any(r => (r.FullName == typeof(IMetricProvider).FullName)) || (e.Interfaces.Any(r => r.FullName == typeof(ILongRunningMetricProvider).FullName))).ToList();
219220

220221
var isPlugin = false;
221222

@@ -225,20 +226,6 @@ private void DetectPlugins()
225226
ICheckTypeList.Add(res);
226227
isPlugin = true;
227228
}
228-
229-
//var typeDefinitions = def.MainModule.Types.Where(f=> f.CustomAttributes.Any(a=>a.AttributeType.FullName == typeof(PerformanceCounterGroupingAttribute).FullName ) ).ToList();
230-
231-
//if (typeDefinitions.Any())
232-
//{
233-
// logger.Trace($"Found slice {info.FullName}");
234-
235-
// var loadSlices = instanceProxy.LoadSlices(info.FullName);
236-
237-
// sliceCheckList.Add(loadSlices);
238-
239-
// isPlugin = true;
240-
// }
241-
242229

243230
if (isPlugin)
244231
{
@@ -253,13 +240,16 @@ private void DetectPlugins()
253240
}
254241
}
255242

256-
var checkNames = ICheckTypeList.Select(e => e.GetType().FullName).ToList();
243+
var checkNames = ICheckTypeList.ToList();
257244

258245
foreach (var jsonFiles in workingFiles.GetFiles("*.json"))
259246
{
260-
if (checkNames.Contains(Path.GetFileNameWithoutExtension(jsonFiles.Name)))
247+
var filename = Path.GetFileNameWithoutExtension(jsonFiles.Name);
248+
if (checkNames.Contains(filename))
261249
{
262-
instanceProxy.PluginSettings.Add(Path.GetFileNameWithoutExtension(jsonFiles.Name), JObject.Parse(File.ReadAllText(jsonFiles.FullName)) as dynamic);
250+
251+
//instanceProxy.PluginSettings.Add(filename, value);
252+
instanceProxy.AddSettings(filename, File.ReadAllText(jsonFiles.FullName));
263253
}
264254
}
265255

@@ -274,7 +264,7 @@ private void DetectPlugins()
274264
watcher.Renamed += delegate { pluginChangeDetected = true; };
275265
watcher.EnableRaisingEvents = true;
276266

277-
logger.Trace("Plugins found!");
267+
logger.Trace("Plugin Load Complete");
278268
}
279269
FileSystemWatcher watcher;
280270
ExpandoObjectConverter eoConverter = new ExpandoObjectConverter();
@@ -335,7 +325,7 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)
335325
return;
336326
}
337327

338-
pluginCollection.Add(result);
328+
pluginCollection.AddRange(result);
339329

340330
}
341331
catch (Exception ex)
@@ -348,7 +338,7 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)
348338

349339
logger.Info("Polling long checks");
350340

351-
try
341+
try
352342
{
353343
var longRunningChecks = instanceProxy.GetLongRunningChecks();
354344

@@ -363,6 +353,11 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)
363353

364354
}
365355
}
356+
catch (RemotingException remoting)
357+
{
358+
logger.Warn("Remoting exception, will reload plugins", remoting);
359+
pluginChangeDetected = true;
360+
}
366361
catch (Exception exception)
367362
{
368363
logger.Warn(exception, "Error on polling for long checks");

0 commit comments

Comments
 (0)