Skip to content

Commit

Permalink
Scripting: Move script_cache into _nodes/stats (#59265)
Browse files Browse the repository at this point in the history
Updated `_nodes/stats`:
 * Remove `script_cache`
 * Update `script` in `_node/stats` to include stats per context:

```
      "script": {
        "compilations": 1,
        "cache_evictions": 0,
        "compilation_limit_triggered": 0,
        "contexts":[
          {
            "context": "aggregation_selector",
            "compilations": 0,
            "cache_evictions": 0,
            "compilation_limit_triggered": 0
          },

```

Refs: #50152
  • Loading branch information
stu-elastic authored Jul 9, 2020
1 parent 2f60ff4 commit 8d8bd3d
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 284 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ tasks.register("verifyVersions") {
* after the backport of the backcompat code is complete.
*/

boolean bwc_tests_enabled = true
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
boolean bwc_tests_enabled = false
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/59265" /* place a PR link here when committing bwc changes */
if (bwc_tests_enabled == false) {
if (bwc_tests_disabled_issue.isEmpty()) {
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.action.admin.cluster.node.stats;

import org.elasticsearch.Version;
import org.elasticsearch.action.support.nodes.BaseNodeResponse;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
Expand All @@ -38,7 +37,6 @@
import org.elasticsearch.monitor.os.OsStats;
import org.elasticsearch.monitor.process.ProcessStats;
import org.elasticsearch.node.AdaptiveSelectionStats;
import org.elasticsearch.script.ScriptCacheStats;
import org.elasticsearch.script.ScriptStats;
import org.elasticsearch.threadpool.ThreadPoolStats;
import org.elasticsearch.transport.TransportStats;
Expand Down Expand Up @@ -83,9 +81,6 @@ public class NodeStats extends BaseNodeResponse implements ToXContentFragment {
@Nullable
private ScriptStats scriptStats;

@Nullable
private ScriptCacheStats scriptCacheStats;

@Nullable
private DiscoveryStats discoveryStats;

Expand Down Expand Up @@ -113,11 +108,6 @@ public NodeStats(StreamInput in) throws IOException {
discoveryStats = in.readOptionalWriteable(DiscoveryStats::new);
ingestStats = in.readOptionalWriteable(IngestStats::new);
adaptiveSelectionStats = in.readOptionalWriteable(AdaptiveSelectionStats::new);
if (in.getVersion().onOrAfter(Version.V_7_8_0)) {
scriptCacheStats = in.readOptionalWriteable(ScriptCacheStats::new);
} else {
scriptCacheStats = null;
}
}

public NodeStats(DiscoveryNode node, long timestamp, @Nullable NodeIndicesStats indices,
Expand All @@ -127,8 +117,7 @@ public NodeStats(DiscoveryNode node, long timestamp, @Nullable NodeIndicesStats
@Nullable ScriptStats scriptStats,
@Nullable DiscoveryStats discoveryStats,
@Nullable IngestStats ingestStats,
@Nullable AdaptiveSelectionStats adaptiveSelectionStats,
@Nullable ScriptCacheStats scriptCacheStats) {
@Nullable AdaptiveSelectionStats adaptiveSelectionStats) {
super(node);
this.timestamp = timestamp;
this.indices = indices;
Expand All @@ -144,7 +133,6 @@ public NodeStats(DiscoveryNode node, long timestamp, @Nullable NodeIndicesStats
this.discoveryStats = discoveryStats;
this.ingestStats = ingestStats;
this.adaptiveSelectionStats = adaptiveSelectionStats;
this.scriptCacheStats = scriptCacheStats;
}

public long getTimestamp() {
Expand Down Expand Up @@ -239,11 +227,6 @@ public AdaptiveSelectionStats getAdaptiveSelectionStats() {
return adaptiveSelectionStats;
}

@Nullable
public ScriptCacheStats getScriptCacheStats() {
return scriptCacheStats;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand All @@ -266,9 +249,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalWriteable(discoveryStats);
out.writeOptionalWriteable(ingestStats);
out.writeOptionalWriteable(adaptiveSelectionStats);
if (out.getVersion().onOrAfter(Version.V_7_8_0)) {
out.writeOptionalWriteable(scriptCacheStats);
}
}

@Override
Expand Down Expand Up @@ -332,9 +312,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (getAdaptiveSelectionStats() != null) {
getAdaptiveSelectionStats().toXContent(builder, params);
}
if (getScriptCacheStats() != null) {
getScriptCacheStats().toXContent(builder, params);
}
return builder;
}
}
3 changes: 1 addition & 2 deletions server/src/main/java/org/elasticsearch/node/NodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ public NodeStats stats(CommonStatsFlags indices, boolean os, boolean process, bo
script ? scriptService.stats() : null,
discoveryStats ? discovery.stats() : null,
ingest ? ingestService.stats() : null,
adaptiveSelection ? responseCollectorService.getAdaptiveStats(searchTransportService.getPendingSearchRequests()) : null,
scriptCache ? scriptService.cacheStats() : null
adaptiveSelection ? responseCollectorService.getAdaptiveStats(searchTransportService.getPendingSearchRequests()) : null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ static <T extends Throwable> void rethrow(Throwable t) throws T {
throw (T) t;
}

public ScriptStats stats() {
return scriptMetrics.stats();
public ScriptContextStats stats(String context) {
return scriptMetrics.stats(context);
}

/**
Expand Down
147 changes: 0 additions & 147 deletions server/src/main/java/org/elasticsearch/script/ScriptCacheStats.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.elasticsearch.script;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Objects;

public class ScriptContextStats implements Writeable, ToXContentFragment, Comparable<ScriptContextStats> {
private final String context;
private final long compilations;
private final long cacheEvictions;
private final long compilationLimitTriggered;

public ScriptContextStats(String context, long compilations, long cacheEvictions, long compilationLimitTriggered) {
this.context = Objects.requireNonNull(context);
this.compilations = compilations;
this.cacheEvictions = cacheEvictions;
this.compilationLimitTriggered = compilationLimitTriggered;
}

public ScriptContextStats(StreamInput in) throws IOException {
context = in.readString();
compilations = in.readVLong();
cacheEvictions = in.readVLong();
compilationLimitTriggered = in.readVLong();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(context);
out.writeVLong(compilations);
out.writeVLong(cacheEvictions);
out.writeVLong(compilationLimitTriggered);
}

public String getContext() {
return context;
}

public long getCompilations() {
return compilations;
}

public long getCacheEvictions() {
return cacheEvictions;
}

public long getCompilationLimitTriggered() {
return compilationLimitTriggered;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(Fields.CONTEXT, getContext());
builder.field(Fields.COMPILATIONS, getCompilations());
builder.field(Fields.CACHE_EVICTIONS, getCacheEvictions());
builder.field(Fields.COMPILATION_LIMIT_TRIGGERED, getCompilationLimitTriggered());
builder.endObject();
return builder;
}

@Override
public int compareTo(ScriptContextStats o) {
return this.context.compareTo(o.context);
}

static final class Fields {
static final String CONTEXT = "context";
static final String COMPILATIONS = "compilations";
static final String CACHE_EVICTIONS = "cache_evictions";
static final String COMPILATION_LIMIT_TRIGGERED = "compilation_limit_triggered";
}
}
14 changes: 9 additions & 5 deletions server/src/main/java/org/elasticsearch/script/ScriptMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public class ScriptMetrics {
final CounterMetric cacheEvictionsMetric = new CounterMetric();
final CounterMetric compilationLimitTriggered = new CounterMetric();

public ScriptStats stats() {
return new ScriptStats(compilationsMetric.count(), cacheEvictionsMetric.count(), compilationLimitTriggered.count());
}

public void onCompilation() {
compilationsMetric.inc();
}
Expand All @@ -41,4 +37,12 @@ public void onCacheEviction() {
public void onCompilationLimit() {
compilationLimitTriggered.inc();
}
}

public ScriptContextStats stats(String context) {
return new ScriptContextStats(
context,
compilationsMetric.count(),
cacheEvictionsMetric.count(),
compilationLimitTriggered.count()
);
}}
Loading

0 comments on commit 8d8bd3d

Please sign in to comment.