Search in sources :

Example 1 with CounterSupplier

use of org.opensearch.ml.stats.suppliers.CounterSupplier in project ml-commons by opensearch-project.

the class MLStatTests method testIncrementDecrement.

public void testIncrementDecrement() {
    MLStat<Long> stat = new MLStat<>(false, new CounterSupplier());
    for (Long i = 0L; i < 100; i++) {
        Assert.assertEquals("increment does not work", i, stat.getValue());
        stat.increment();
    }
    for (Long i = 100L; i > 0; i--) {
        Assert.assertEquals("decrement does not work", i, stat.getValue());
        stat.decrement();
    }
    // Ensure that no problems occur for a stat that cannot be incremented/decremented
    MLStat<String> nonIncDecStat = new MLStat<>(false, new TestSupplier());
    nonIncDecStat.increment();
    nonIncDecStat.decrement();
}
Also used : CounterSupplier(org.opensearch.ml.stats.suppliers.CounterSupplier)

Example 2 with CounterSupplier

use of org.opensearch.ml.stats.suppliers.CounterSupplier in project ml-commons by opensearch-project.

the class MachineLearningPlugin method createComponents.

@Override
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, ResourceWatcherService resourceWatcherService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, Environment environment, NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<RepositoriesService> repositoriesServiceSupplier) {
    this.client = client;
    this.threadPool = threadPool;
    this.clusterService = clusterService;
    Settings settings = environment.settings();
    JvmService jvmService = new JvmService(environment.settings());
    MLCircuitBreakerService mlCircuitBreakerService = new MLCircuitBreakerService(jvmService).init();
    Map<String, MLStat<?>> stats = new ConcurrentHashMap<>();
    stats.put(StatNames.ML_EXECUTING_TASK_COUNT, new MLStat<>(false, new CounterSupplier()));
    stats.put(StatNames.ML_TOTAL_REQUEST_COUNT, new MLStat<>(false, new CounterSupplier()));
    stats.put(StatNames.ML_TOTAL_FAILURE_COUNT, new MLStat<>(false, new CounterSupplier()));
    stats.put(StatNames.ML_TOTAL_MODEL_COUNT, new MLStat<>(false, new CounterSupplier()));
    this.mlStats = new MLStats(stats);
    mlIndicesHandler = new MLIndicesHandler(clusterService, client);
    mlTaskManager = new MLTaskManager(client, mlIndicesHandler);
    mlInputDatasetHandler = new MLInputDatasetHandler(client);
    MLTaskDispatcher mlTaskDispatcher = new MLTaskDispatcher(clusterService, client);
    mlTrainingTaskRunner = new MLTrainingTaskRunner(threadPool, clusterService, client, mlTaskManager, mlStats, mlIndicesHandler, mlInputDatasetHandler, mlTaskDispatcher, mlCircuitBreakerService);
    mlPredictTaskRunner = new MLPredictTaskRunner(threadPool, clusterService, client, mlTaskManager, mlStats, mlInputDatasetHandler, mlTaskDispatcher, mlCircuitBreakerService);
    mlTrainAndPredictTaskRunner = new MLTrainAndPredictTaskRunner(threadPool, clusterService, client, mlTaskManager, mlStats, mlInputDatasetHandler, mlTaskDispatcher, mlCircuitBreakerService);
    mlExecuteTaskRunner = new MLExecuteTaskRunner(threadPool, clusterService, client, mlTaskManager, mlStats, mlInputDatasetHandler, mlTaskDispatcher, mlCircuitBreakerService);
    // Register thread-safe ML objects here.
    LocalSampleCalculator localSampleCalculator = new LocalSampleCalculator(client, settings);
    MLEngineClassLoader.register(FunctionName.LOCAL_SAMPLE_CALCULATOR, localSampleCalculator);
    AnomalyLocalizerImpl anomalyLocalizer = new AnomalyLocalizerImpl(client, settings);
    MLEngineClassLoader.register(FunctionName.ANOMALY_LOCALIZATION, anomalyLocalizer);
    MLSearchHandler mlSearchHandler = new MLSearchHandler(client, xContentRegistry);
    return ImmutableList.of(mlStats, mlTaskManager, mlIndicesHandler, mlInputDatasetHandler, mlTrainingTaskRunner, mlPredictTaskRunner, mlTrainAndPredictTaskRunner, mlExecuteTaskRunner, mlSearchHandler);
}
Also used : MLTrainAndPredictTaskRunner(org.opensearch.ml.task.MLTrainAndPredictTaskRunner) MLInputDatasetHandler(org.opensearch.ml.indices.MLInputDatasetHandler) MLStat(org.opensearch.ml.stats.MLStat) MLTaskManager(org.opensearch.ml.task.MLTaskManager) MLExecuteTaskRunner(org.opensearch.ml.task.MLExecuteTaskRunner) MLTrainingTaskRunner(org.opensearch.ml.task.MLTrainingTaskRunner) LocalSampleCalculator(org.opensearch.ml.engine.algorithms.sample.LocalSampleCalculator) CounterSupplier(org.opensearch.ml.stats.suppliers.CounterSupplier) MLIndicesHandler(org.opensearch.ml.indices.MLIndicesHandler) MLTaskDispatcher(org.opensearch.ml.task.MLTaskDispatcher) AnomalyLocalizerImpl(org.opensearch.ml.engine.algorithms.anomalylocalization.AnomalyLocalizerImpl) JvmService(org.opensearch.monitor.jvm.JvmService) MLStats(org.opensearch.ml.stats.MLStats) MLPredictTaskRunner(org.opensearch.ml.task.MLPredictTaskRunner) MLSearchHandler(org.opensearch.ml.action.handler.MLSearchHandler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) MLCircuitBreakerService(org.opensearch.ml.common.breaker.MLCircuitBreakerService)

Example 3 with CounterSupplier

use of org.opensearch.ml.stats.suppliers.CounterSupplier in project ml-commons by opensearch-project.

the class MLStatsNodesTransportActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    clusterStatName1 = "clusterStat1";
    nodeStatName1 = "nodeStat1";
    statsMap = new HashMap<String, MLStat<?>>() {

        {
            put(nodeStatName1, new MLStat<>(false, new CounterSupplier()));
            put(clusterStatName1, new MLStat<>(true, new CounterSupplier()));
            put(InternalStatNames.JVM_HEAP_USAGE.getName(), new MLStat<>(true, new SettableSupplier()));
        }
    };
    mlStats = new MLStats(statsMap);
    Environment environment = mock(Environment.class);
    Settings settings = Settings.builder().build();
    when(environment.settings()).thenReturn(settings);
    action = new MLStatsNodesTransportAction(client().threadPool(), clusterService(), mock(TransportService.class), mock(ActionFilters.class), mlStats, environment);
}
Also used : CounterSupplier(org.opensearch.ml.stats.suppliers.CounterSupplier) SettableSupplier(org.opensearch.ml.stats.suppliers.SettableSupplier) MLStats(org.opensearch.ml.stats.MLStats) MLStat(org.opensearch.ml.stats.MLStat) Environment(org.opensearch.env.Environment) Settings(org.opensearch.common.settings.Settings) Before(org.junit.Before)

Example 4 with CounterSupplier

use of org.opensearch.ml.stats.suppliers.CounterSupplier in project ml-commons by opensearch-project.

the class RestStatsMLActionTests method setup.

@Before
public void setup() {
    Map<String, MLStat<?>> statMap = ImmutableMap.<String, MLStat<?>>builder().put(StatNames.ML_EXECUTING_TASK_COUNT, new MLStat<>(false, new CounterSupplier())).build();
    mlStats = new MLStats(statMap);
    restAction = new RestStatsMLAction(mlStats);
}
Also used : CounterSupplier(org.opensearch.ml.stats.suppliers.CounterSupplier) MLStats(org.opensearch.ml.stats.MLStats) MLStat(org.opensearch.ml.stats.MLStat) Before(org.junit.Before)

Example 5 with CounterSupplier

use of org.opensearch.ml.stats.suppliers.CounterSupplier in project ml-commons by opensearch-project.

the class MLStatTests method testSetGetValue.

public void testSetGetValue() {
    MLStat<Long> stat1 = new MLStat<>(false, new CounterSupplier());
    Assert.assertEquals("GetValue returns the incorrect value", 0L, (long) (stat1.getValue()));
    stat1.setValue(1L);
    Assert.assertEquals("GetValue returns the incorrect value", 0L, (long) (stat1.getValue()));
    MLStat<String> stat2 = new MLStat<>(false, new TestSupplier());
    Assert.assertEquals("GetValue returns the incorrect value", "test", stat2.getValue());
    stat2.setValue(1L);
    Assert.assertEquals("GetValue returns the incorrect value", "test", stat2.getValue());
    MLStat<Long> stat3 = new MLStat<>(false, new SettableSupplier());
    Assert.assertEquals("GetValue returns the incorrect value", 0L, (long) stat3.getValue());
    stat3.setValue(1L);
    Assert.assertEquals("GetValue returns the incorrect value", 1L, (long) stat3.getValue());
}
Also used : CounterSupplier(org.opensearch.ml.stats.suppliers.CounterSupplier) SettableSupplier(org.opensearch.ml.stats.suppliers.SettableSupplier)

Aggregations

CounterSupplier (org.opensearch.ml.stats.suppliers.CounterSupplier)6 Before (org.junit.Before)3 MLStat (org.opensearch.ml.stats.MLStat)3 MLStats (org.opensearch.ml.stats.MLStats)3 Settings (org.opensearch.common.settings.Settings)2 SettableSupplier (org.opensearch.ml.stats.suppliers.SettableSupplier)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ClusterSettings (org.opensearch.common.settings.ClusterSettings)1 IndexScopedSettings (org.opensearch.common.settings.IndexScopedSettings)1 Environment (org.opensearch.env.Environment)1 MLSearchHandler (org.opensearch.ml.action.handler.MLSearchHandler)1 MLCircuitBreakerService (org.opensearch.ml.common.breaker.MLCircuitBreakerService)1 AnomalyLocalizerImpl (org.opensearch.ml.engine.algorithms.anomalylocalization.AnomalyLocalizerImpl)1 LocalSampleCalculator (org.opensearch.ml.engine.algorithms.sample.LocalSampleCalculator)1 MLIndicesHandler (org.opensearch.ml.indices.MLIndicesHandler)1 MLInputDatasetHandler (org.opensearch.ml.indices.MLInputDatasetHandler)1 MLExecuteTaskRunner (org.opensearch.ml.task.MLExecuteTaskRunner)1 MLPredictTaskRunner (org.opensearch.ml.task.MLPredictTaskRunner)1 MLTaskDispatcher (org.opensearch.ml.task.MLTaskDispatcher)1 MLTaskManager (org.opensearch.ml.task.MLTaskManager)1