mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-04 11:20:53 +01:00
Hardcode instance id for development instances (#2054)
We need this to recognize our development instances in the collected prometheus metrics.
This commit is contained in:
@@ -86,6 +86,8 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
*/
|
||||
public static final String STAGE_PROPERTY = "scm.stage";
|
||||
|
||||
public static final String DEVELOPMENT_INSTANCE_ID = "00000000-0000-0000-0000-000000000000";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -286,6 +288,9 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
}
|
||||
|
||||
private String readOrCreateInstanceId() throws IOException {
|
||||
if (stage == Stage.DEVELOPMENT) {
|
||||
return DEVELOPMENT_INSTANCE_ID;
|
||||
}
|
||||
File configDirectory = new File(baseDirectory, "config");
|
||||
IOUtil.mkdirs(configDirectory);
|
||||
File instanceIdFile = new File(configDirectory, ".instance-id");
|
||||
|
||||
@@ -34,6 +34,8 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static sonia.scm.BasicContextProvider.DEVELOPMENT_INSTANCE_ID;
|
||||
import static sonia.scm.BasicContextProvider.STAGE_PROPERTY;
|
||||
|
||||
class BasicContextProviderTest {
|
||||
|
||||
@@ -129,6 +131,29 @@ class BasicContextProviderTest {
|
||||
assertThat(provider.getInstanceId()).isEqualTo(firstInstanceId);
|
||||
}
|
||||
|
||||
}
|
||||
@Nested
|
||||
class WithStageDevelopment {
|
||||
|
||||
private String stage;
|
||||
|
||||
@BeforeEach
|
||||
void setStage() {
|
||||
stage = new BasicContextProvider().getStage().name();
|
||||
System.setProperty(STAGE_PROPERTY, Stage.DEVELOPMENT.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnHardCodeInstanceIfIfStageDevelopment() {
|
||||
BasicContextProvider basicContextProvider = new BasicContextProvider();
|
||||
String instanceId = basicContextProvider.getInstanceId();
|
||||
|
||||
assertThat(instanceId).isEqualTo(DEVELOPMENT_INSTANCE_ID);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void resetStage() {
|
||||
System.setProperty(STAGE_PROPERTY, stage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user