Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onExit() {
private List<GRPCExporter.ExportData> dataList() {
List<GRPCExporter.ExportData> dataList = new LinkedList<>();
dataList.add(exporter.new ExportData(metaInfo, new MockIndicator()));
dataList.add(exporter.new ExportData(metaInfo, new MockIntValueIndicatior()));
dataList.add(exporter.new ExportData(metaInfo, new MockIntValueIndicator()));
dataList.add(exporter.new ExportData(metaInfo, new MockLongValueIndicator()));
dataList.add(exporter.new ExportData(metaInfo, new MockDoubleValueIndicator()));
return dataList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Created by dengming, 2019.04.20
*/
public class MockIntValueIndicatior extends MockIndicator implements IntValueHolder {
public class MockIntValueIndicator extends MockIndicator implements IntValueHolder {
@Override
public int getValue() {
return 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@

package org.apache.skywalking.oap.server.core.alarm.provider;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
import org.joda.time.LocalDateTime;
import org.joda.time.Minutes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
* Alarm core includes metric values in certain time windows based on alarm settings. By using its internal timer
* trigger and the alarm rules to decides whether send the alarm to database and webhook(s)
Expand All @@ -50,11 +51,8 @@ public class AlarmCore {

String indicatorName = rule.getIndicatorName();

List<RunningRule> runningRules = runningContext.get(indicatorName);
if (runningRules == null) {
runningRules = new ArrayList<>();
runningContext.put(indicatorName, runningRules);
}
List<RunningRule> runningRules = runningContext.computeIfAbsent(indicatorName, key -> new ArrayList<>());

runningRules.add(runningRule);
});
}
Expand All @@ -71,7 +69,7 @@ public void start(List<AlarmCallback> allCallbacks) {
List<AlarmMessage> alarmMessageList = new ArrayList<>(30);
LocalDateTime checkTime = LocalDateTime.now();
int minutes = Minutes.minutesBetween(lastExecuteTime, checkTime).getMinutes();
boolean[] hasExecute = new boolean[] {false};
boolean[] hasExecute = new boolean[]{false};
runningContext.values().forEach(ruleList -> ruleList.forEach(runningRule -> {
if (minutes > 0) {
runningRule.moveTo(checkTime);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.alarm.provider;

import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.alarm.AlarmModule;
import org.apache.skywalking.oap.server.library.module.ModuleProvider;
import org.junit.Before;
import org.junit.Test;
import org.powermock.reflect.Whitebox;

import java.util.Iterator;
import java.util.ServiceLoader;

import static org.junit.Assert.*;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;

/**
* Created by dengming, 2019.04.22
*/
public class AlarmModuleProviderTest {

private AlarmModuleProvider moduleProvider;

@Before
public void setUp() throws Exception {
ServiceLoader<ModuleProvider> serviceLoader = ServiceLoader.load(ModuleProvider.class);
Iterator<ModuleProvider> providerIterator = serviceLoader.iterator();

assertTrue(providerIterator.hasNext());

moduleProvider = (AlarmModuleProvider) providerIterator.next();

moduleProvider.createConfigBeanIfAbsent();

moduleProvider.prepare();
}

@Test
public void name() {
assertEquals("default", moduleProvider.name());
}

@Test
public void module() {
assertEquals(AlarmModule.class, moduleProvider.module());
}

@Test
public void start() throws Exception {
moduleProvider.start();
}

@Test
public void notifyAfterCompleted() throws Exception {

NotifyHandler handler = mock(NotifyHandler.class);

doNothing().when(handler).initCache(null);

Whitebox.setInternalState(moduleProvider, "notifyHandler", handler);
moduleProvider.notifyAfterCompleted();
}

@Test
public void requiredModules() {
String[] modules = moduleProvider.requiredModules();
assertArrayEquals(new String[]{CoreModule.NAME}, modules);
}
}
Loading