зеркало из https://github.com/microsoft/Dhalion.git
Add Outcome references to reconstruct provenance
This commit is contained in:
Родитель
a313cb4faf
Коммит
9f1830763c
|
@ -11,6 +11,7 @@ import com.microsoft.dhalion.core.Measurement;
|
|||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* A {@link MetricsProvider} implements common utility methods to produce {@link Measurement}s. In some cases it will
|
||||
|
@ -43,6 +44,24 @@ public interface MetricsProvider {
|
|||
throw new UnsupportedOperationException("This method is not implemented in the metrics provider");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param startTime metric aggregation window start time, endTime = startTime - duration
|
||||
* @param duration the duration for which the metric was aggregated
|
||||
* @param metric ids of the metrics
|
||||
* @param component ids of the components for which the metric is needed
|
||||
* @return collection of {@link Measurement}s
|
||||
* @see #getMeasurements(Instant, Duration, Collection, Collection)
|
||||
*/
|
||||
default Collection<Measurement> getMeasurements(Instant startTime,
|
||||
Duration duration,
|
||||
String metric,
|
||||
String component) {
|
||||
return getMeasurements(startTime,
|
||||
duration,
|
||||
Collections.singletonList(metric),
|
||||
Collections.singletonList(component));
|
||||
}
|
||||
|
||||
/**
|
||||
* Release all acquired resources and prepare for termination of this instance
|
||||
*/
|
||||
|
|
|
@ -9,18 +9,35 @@ package com.microsoft.dhalion.core;
|
|||
import com.microsoft.dhalion.api.IResolver;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* {@link Action} is a representation of a action taken by {@link IResolver} to improve system health.
|
||||
*/
|
||||
public class Action extends Outcome {
|
||||
public Action(String type, Instant instant, Collection<String> assignments) {
|
||||
private final Collection<Diagnosis> diagnosis = new ArrayList<>();
|
||||
|
||||
public Action(String type, Instant instant, Collection<String> assignments, Collection<Diagnosis> diagnosis) {
|
||||
super(type, instant, assignments);
|
||||
if (diagnosis != null) {
|
||||
this.diagnosis.addAll(diagnosis);
|
||||
}
|
||||
}
|
||||
|
||||
public Action(int id, String symptomType, Instant instant, Collection<String> assignments) {
|
||||
super(id, symptomType, instant, assignments);
|
||||
public Action(int id, String type, Instant instant, Collection<String> assignments, Collection<Diagnosis> diagnosis) {
|
||||
super(id, type, instant, assignments);
|
||||
if (diagnosis != null) {
|
||||
this.diagnosis.addAll(diagnosis);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link Diagnosis} referred to when this {@link Action} was created
|
||||
*/
|
||||
public Collection<Diagnosis> diagnosis() {
|
||||
return Collections.unmodifiableCollection(diagnosis);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -133,7 +133,8 @@ public class ActionTable extends OutcomeTable<Action> {
|
|||
return new Action(id.get(index),
|
||||
type.get(index),
|
||||
Instant.ofEpochMilli(timeStamp.get(index)),
|
||||
Collections.singletonList(assignment.get(index)));
|
||||
Collections.singletonList(assignment.get(index)),
|
||||
null);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,19 +7,44 @@
|
|||
package com.microsoft.dhalion.core;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* A {@link Diagnosis} is a representation of a possible causes of one or more {@link Symptom}s. For e.g. resource
|
||||
* under-provisioning
|
||||
*/
|
||||
public class Diagnosis extends Outcome {
|
||||
public Diagnosis(String type, Instant instant, Collection<String> assignments) {
|
||||
// symtoms referred to create this instance
|
||||
private final Collection<Symptom> symptoms = new ArrayList<>();
|
||||
|
||||
public Diagnosis(String type,
|
||||
Instant instant,
|
||||
Collection<String> assignments,
|
||||
Collection<Symptom> symptoms) {
|
||||
super(type, instant, assignments);
|
||||
if (symptoms != null) {
|
||||
this.symptoms.addAll(symptoms);
|
||||
}
|
||||
}
|
||||
|
||||
public Diagnosis(int id, String symptomType, Instant instant, Collection<String> assignments) {
|
||||
super(id, symptomType, instant, assignments);
|
||||
public Diagnosis(int id,
|
||||
String type,
|
||||
Instant instant,
|
||||
Collection<String> assignments,
|
||||
Collection<Symptom> symptoms) {
|
||||
super(id, type, instant, assignments);
|
||||
if (symptoms != null) {
|
||||
this.symptoms.addAll(symptoms);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link Symptom}s referred to when this {@link Diagnosis} was created
|
||||
*/
|
||||
public Collection<Symptom> symptoms() {
|
||||
return Collections.unmodifiableCollection(symptoms);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -133,7 +133,8 @@ public class DiagnosisTable extends OutcomeTable<Diagnosis> {
|
|||
return new Diagnosis(id.get(index),
|
||||
type.get(index),
|
||||
Instant.ofEpochMilli(timeStamp.get(index)),
|
||||
Collections.singletonList(assignment.get(index)));
|
||||
Collections.singletonList(assignment.get(index)),
|
||||
null);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -172,6 +172,16 @@ public class MeasurementsTable {
|
|||
return new MeasurementsTable(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains all {@link Measurement}s created at the given timestamp.
|
||||
*
|
||||
* @param timestamp {@link Measurement} creation time.
|
||||
* @return {@link MeasurementsTable} containing filtered {@link Measurement}s
|
||||
*/
|
||||
public MeasurementsTable instant(Instant timestamp) {
|
||||
return between(timestamp, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains only the {@link Measurement}s whose value is between <code>low</code> and <code>high</code>, both
|
||||
* inclusive.
|
||||
|
|
|
@ -9,8 +9,8 @@ package com.microsoft.dhalion.core;
|
|||
import com.microsoft.dhalion.api.IDetector;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ abstract class Outcome {
|
|||
private final Instant instant;
|
||||
|
||||
// ids of objects to which this outcome can be attributed to, for e.g. slow instance's id
|
||||
private final Collection<String> assignments;
|
||||
private final Collection<String> assignments = new ArrayList<>();
|
||||
|
||||
Outcome(String type, Instant instant, Collection<String> assignments) {
|
||||
this(idGenerator.incrementAndGet(), type, instant, assignments);
|
||||
|
@ -40,7 +40,9 @@ abstract class Outcome {
|
|||
this.id = id;
|
||||
this.type = type;
|
||||
this.instant = instant;
|
||||
this.assignments = Collections.unmodifiableCollection(assignments);
|
||||
if (assignments != null) {
|
||||
this.assignments.addAll(assignments);
|
||||
}
|
||||
}
|
||||
|
||||
public int id() {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package com.microsoft.dhalion.core;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
|
@ -14,12 +15,35 @@ import java.util.Collection;
|
|||
* distributed application. For e.g. identification of irregular processing latency.
|
||||
*/
|
||||
public class Symptom extends Outcome {
|
||||
public Symptom(String symptomType, Instant instant, Collection<String> assignments) {
|
||||
// measurements referred to create this instance
|
||||
private final Collection<Measurement> measurements = new ArrayList<>();
|
||||
|
||||
public Symptom(String symptomType,
|
||||
Instant instant,
|
||||
Collection<String> assignments,
|
||||
Collection<Measurement> measurements) {
|
||||
super(symptomType, instant, assignments);
|
||||
if (measurements != null) {
|
||||
this.measurements.addAll(measurements);
|
||||
}
|
||||
}
|
||||
|
||||
public Symptom(int id, String symptomType, Instant instant, Collection<String> assignments) {
|
||||
public Symptom(int id,
|
||||
String symptomType,
|
||||
Instant instant,
|
||||
Collection<String> assignments,
|
||||
Collection<Measurement> measurements) {
|
||||
super(id, symptomType, instant, assignments);
|
||||
if (measurements != null) {
|
||||
this.measurements.addAll(measurements);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link Measurement}s referred to when this {@link Symptom} was created
|
||||
*/
|
||||
public Collection<Measurement> measurements() {
|
||||
return measurements;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -133,7 +133,8 @@ public class SymptomsTable extends OutcomeTable<Symptom> {
|
|||
return new Symptom(id.get(index),
|
||||
type.get(index),
|
||||
Instant.ofEpochMilli(timeStamp.get(index)),
|
||||
Collections.singletonList(assignment.get(index)));
|
||||
Collections.singletonList(assignment.get(index)),
|
||||
null);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ public class PoliciesExecutor {
|
|||
policyContextMap.get(policy).symptomsTableBuilder.addAll(symptoms);
|
||||
|
||||
Collection<Diagnosis> diagnosis = policy.executeDiagnosers(symptoms);
|
||||
policyContextMap.get(policy).diagnsisTableBuilder.addAll(diagnosis);
|
||||
policyContextMap.get(policy).diagnosisTableBuilder.addAll(diagnosis);
|
||||
|
||||
Collection<Action> actions = policy.executeResolvers(diagnosis);
|
||||
policyContextMap.get(policy).actionTableBuilder.addAll(actions);
|
||||
|
@ -99,13 +99,13 @@ public class PoliciesExecutor {
|
|||
public static class ExecutionContext {
|
||||
private final MeasurementsTable.Builder measurementsTableBuilder;
|
||||
private final SymptomsTable.Builder symptomsTableBuilder;
|
||||
private final DiagnosisTable.Builder diagnsisTableBuilder;
|
||||
private final DiagnosisTable.Builder diagnosisTableBuilder;
|
||||
private final ActionTable.Builder actionTableBuilder;
|
||||
|
||||
private ExecutionContext() {
|
||||
measurementsTableBuilder = new MeasurementsTable.Builder();
|
||||
symptomsTableBuilder = new SymptomsTable.Builder();
|
||||
diagnsisTableBuilder = new DiagnosisTable.Builder();
|
||||
diagnosisTableBuilder = new DiagnosisTable.Builder();
|
||||
actionTableBuilder = new ActionTable.Builder();
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class PoliciesExecutor {
|
|||
}
|
||||
|
||||
public DiagnosisTable diagnosis() {
|
||||
return diagnsisTableBuilder.get();
|
||||
return diagnosisTableBuilder.get();
|
||||
}
|
||||
|
||||
public ActionTable actions() {
|
||||
|
|
|
@ -37,7 +37,7 @@ public class SymptomsTableTest {
|
|||
int value = 10;
|
||||
for (int id : ids) {
|
||||
for (String type : types) {
|
||||
symptoms.add(new Symptom(id, type, Instant.ofEpochMilli(value), attributions));
|
||||
symptoms.add(new Symptom(id, type, Instant.ofEpochMilli(value), attributions, null));
|
||||
value += 10;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче