apache/skywalking · error · ExpressionParsingException
{}: one of service(), instance() or endpoint() should be inv
Error message
{}: one of service(), instance() or endpoint() should be invoked What it means
Thrown by Expression.parse() in the MAL (Meter Analysis Language) v2 analyzer when the compiled expression's metadata has a null scope type. In MAL every metric expression must terminate in exactly one scope function — service(), instance() or endpoint() — which tells the OAP which level the aggregated metric belongs to. Without it the analyzer cannot build the persistence/source pipeline for the metric.
Source
Thrown at oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/Expression.java:71
}
/**
* Returns the per-rule capture binding the compiled rule carries. The
* {@code Analyzer.doAnalysis} hand-written probes read it once per ingest
* pass and then gate-guard {@code MALDebug.captureXxx(...)} calls on
* the holder's volatile {@code gate} field.
*/
public GateHolder debugHolder() {
return expression.debugHolder();
}
/**
* Returns compile-time metadata extracted from the expression AST.
*/
public ExpressionMetadata parse() {
final ExpressionMetadata metadata = expression.metadata();
if (metadata.getScopeType() == null) {
throw new ExpressionParsingException(
literal + ": one of service(), instance() or endpoint() should be invoked");
}
if (log.isDebugEnabled()) {
log.debug("\"{}\" is parsed", literal);
}
return metadata;
}
/**
* Run the expression with a data map.
*
* @param sampleFamilies a data map includes all of candidates to be analysis.
* @return The result of execution.
*/
public Result run(final Map<String, SampleFamily> sampleFamilies) {
try {
for (final SampleFamily s : sampleFamilies.values()) {
if (s != SampleFamily.EMPTY) {View on GitHub (pinned to 102af09b4a)
Solutions
- Add exactly one scope function at the end of the metric expression: .service(), .instance() or .endpoint(), matching which entity the metric should be attributed to
- Check that the scope call wraps the whole expression, not an inner argument: use (a + b).service(), not a.service(...) + b
- Validate the rule file with a small test that calls new Expression(literal).parse() (the analyzer's own unit-test pattern) before deploying to OAP
- Confirm only one scope decorator appears; multiple scope calls on the same expression are also rejected upstream
Example fix
# before
exp: http_success_request.sum(['service']).rate('PT1M')
# after
exp: http_success_request.sum(['service']).rate('PT1M').service() Defensive patterns
Strategy: validation
Validate before calling
import org.apache.skywalking.oap.meter.analyzer.v2.dsl.Expression;
void validateMalExpression(String literal) {
Expression e = Expression.compile(literal); // or per API: new Expression(literal)
e.parse(); // throws ExpressionParsingException if scopeType is null
} Try / catch
catch (ExpressionParsingException e) { log.error("MAL rule rejected, add .service()/.instance()/.endpoint(): {}", e.getMessage()); } Prevention
- Always end MAL metric expressions with exactly one scope decorator
- Unit-test each new MAL rule by compiling and calling parse() in CI
- Keep a lint checklist for rule reviews: metricName, exp, filter, scope function
When it happens
Trigger: A MAL rule (YAML meter-analyzer config) whose 'exp' field is a valid expression but is missing the trailing scope call, e.g. 'exp: http_requests_total.sum(['service']).rate('PT1M')' without '.service()'. Also triggered when the scope call is applied to a sub-expression in a way the compiler drops (e.g. inside a function argument rather than at the top level), so the AST root never carries a scopeType.
Common situations: Writing new MAL rules by copying PromQL and forgetting the SkyWalking-specific scope decorator; refactoring an expression and accidentally moving service() inside an aggregation argument; enabling a custom rule (meter-analyzer-config) that was never compiled before and fails at OAP startup.
Related errors
- Failed to compile MAL filter expression: {}
- Some configuration files of enabled rules are not found, ena
- Load rule {} failed
- Load meter analyzer configs failed
- Unsupported extractor statement in LAL rule at line {sourceL
AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14).
Data as JSON: /api/errors/cd7c81787be5e4ff.
Report an issue: GitHub.