Browse code

BM-14045 Fix: at least track with a metric when the PF hierarchy is broken

Thomas Cataldo authored on 06/05/2019 12:32:25
Showing 2 changed files
... ...
@@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.core.runtime,
14 14
  net.bluemind.exchange.publicfolders.common,
15 15
  net.bluemind.domain.hook,
16 16
  net.bluemind.directory.service,
17
- net.bluemind.core.task.spi
17
+ net.bluemind.core.task.spi,
18
+ net.bluemind.metrics.registry
18 19
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
19 20
 Automatic-Module-Name: net.bluemind.exchange.publicfolders.hierarchy
... ...
@@ -22,6 +22,9 @@ import java.util.List;
22 22
 import org.slf4j.Logger;
23 23
 import org.slf4j.LoggerFactory;
24 24
 
25
+import com.netflix.spectator.api.Counter;
26
+import com.netflix.spectator.api.Registry;
27
+
25 28
 import net.bluemind.addressbook.api.IAddressBookUids;
26 29
 import net.bluemind.core.api.fault.ServerFault;
27 30
 import net.bluemind.core.container.api.ContainerHierarchyNode;
... ...
@@ -33,10 +36,23 @@ import net.bluemind.directory.api.BaseDirEntry.Kind;
33 36
 import net.bluemind.directory.api.DirEntry;
34 37
 import net.bluemind.directory.api.IDirectory;
35 38
 import net.bluemind.exchange.publicfolders.common.PublicFolders;
39
+import net.bluemind.metrics.registry.IdFactory;
40
+import net.bluemind.metrics.registry.MetricsRegistry;
36 41
 
37 42
 public class PublicFolderHierarchyHook implements IContainersHook {
38 43
 
39 44
 	private static final Logger logger = LoggerFactory.getLogger(PublicFolderHierarchyHook.class);
45
+	private final Registry reg;
46
+	private final IdFactory idf;
47
+
48
+	public PublicFolderHierarchyHook() {
49
+		reg = MetricsRegistry.get();
50
+		idf = new IdFactory("repair-needed", reg, PublicFolderHierarchyHook.class);
51
+	}
52
+
53
+	private Counter failuresCounter(String domainUid) {
54
+		return reg.counter(idf.name("pf.hierarchy").withTag("domain", domainUid));
55
+	}
40 56
 
41 57
 	private IInternalContainersFlatHierarchy hierarchy(BmContext ctx, ContainerDescriptor cd) {
42 58
 		if (cd.domainUid == null || cd.owner == null) {
... ...
@@ -46,7 +62,8 @@ public class PublicFolderHierarchyHook implements IContainersHook {
46 62
 			return ctx.provider().instance(IInternalContainersFlatHierarchy.class, cd.domainUid,
47 63
 					PublicFolders.mailboxGuid(cd.domainUid));
48 64
 		} catch (ServerFault sf) {
49
-			logger.warn("Missing hierarchy container {}", cd);
65
+			logger.warn("Missing PF hierarchy container {}", cd);
66
+			failuresCounter(cd.domainUid).increment();
50 67
 			return null;
51 68
 		}
52 69
 	}
... ...
@@ -83,7 +100,12 @@ public class PublicFolderHierarchyHook implements IContainersHook {
83 100
 				logger.info("Operation with owner.kind {}", owner.kind);
84 101
 				IInternalContainersFlatHierarchy service = hierarchy(ctx, cd);
85 102
 				if (service != null) {
86
-					operation.accept(service);
103
+					try {
104
+						operation.accept(service);
105
+					} catch (ServerFault sf) {
106
+						failuresCounter(cd.domainUid).increment();
107
+						throw sf;
108
+					}
87 109
 				}
88 110
 			}
89 111
 		}
... ...
@@ -129,13 +151,13 @@ public class PublicFolderHierarchyHook implements IContainersHook {
129 151
 	@Override
130 152
 	public void onContainerSubscriptionsChanged(BmContext ctx, ContainerDescriptor cd, List<String> subs,
131 153
 			List<String> unsubs) throws ServerFault {
132
-		// TODO Auto-generated method stub
154
+		// ok
133 155
 
134 156
 	}
135 157
 
136 158
 	@Override
137 159
 	public void onContainerOfflineSyncStatusChanged(BmContext ctx, ContainerDescriptor cd, String subject) {
138
-		// TODO Auto-generated method stub
160
+		// ok
139 161
 	}
140 162
 
141 163
 }