Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT-23889 Fix liveness/readiness probes #874

Merged
merged 3 commits into from
Oct 19, 2023
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 @@ -68,6 +68,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import static java.text.MessageFormat.format;
import static org.alfresco.transform.base.html.OptionsHelper.getOptionNames;
Expand Down Expand Up @@ -115,6 +116,7 @@ public class TransformController
private boolean behindIngres;

TransformEngine transformEngine;
private final AtomicReference<ProbeTransform> probeTransform = new AtomicReference<>();

@PostConstruct
private void initTransformEngine()
Expand Down Expand Up @@ -247,7 +249,17 @@ public String live(HttpServletRequest request)

public ProbeTransform getProbeTransform()
{
return transformEngine.getProbeTransform();
ProbeTransform probe = probeTransform.get();
if (probe != null)
{
return probe;
}
probe = transformEngine.getProbeTransform();
if (probeTransform.compareAndSet(null, probe))
{
return probe;
}
return probeTransform.get();
}

@GetMapping(value = ENDPOINT_TRANSFORM_CONFIG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,15 @@ public String doTransformOrNothing(boolean isLiveProbe, TransformHandler transfo
{
return doNothing(true);
}
return (isLiveProbe && livenessTransformPeriod > 0 &&

String result = (isLiveProbe && livenessTransformPeriod > 0 &&
(transCount <= AVERAGE_OVER_TRANSFORMS || nextTransformTime < System.currentTimeMillis()))
|| !initialised.get()
? doTransform(isLiveProbe, transformHandler)
: doNothing(isLiveProbe);

checkMaxTransformTimeAndCount(isLiveProbe);
return result;
}

private String doNothing(boolean isLiveProbe)
Expand All @@ -196,8 +200,6 @@ private String doNothing(boolean isLiveProbe)

private String doTransform(boolean isLiveProbe, TransformHandler transformHandler)
{
checkMaxTransformTimeAndCount(isLiveProbe);

long start = System.currentTimeMillis();

if (nextTransformTime != 0)
Expand Down Expand Up @@ -230,8 +232,6 @@ private String doTransform(boolean isLiveProbe, TransformHandler transformHandle
// We don't care if the ready or live probe works out if we are 'ready' to take requests.
initialised.set(true);

checkMaxTransformTimeAndCount(isLiveProbe);

return getProbeMessage(isLiveProbe) + "Success - "+message;
}

Expand All @@ -254,7 +254,6 @@ private void checkMaxTransformTimeAndCount(boolean isLiveProbe)

private File getSourceFile(boolean isLiveProbe)
{
incrementTransformerCount();
File sourceFile = createTempFile("probe_source_", "_" + sourceFilename);
try (InputStream inputStream = getClass().getResourceAsStream('/' + sourceFilename))
{
Expand Down