Skip to content

Commit

Permalink
Scripting: Cache stats only in _nodes/stats:
Browse files Browse the repository at this point in the history
 * 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: elastic#50152
  • Loading branch information
stu-elastic committed Jul 1, 2020
1 parent ea39a47 commit 2963351
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 309 deletions.
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,6 +132,10 @@ static <T extends Throwable> void rethrow(Throwable t) throws T {
throw (T) t;
}

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

public ScriptStats stats() {
return scriptMetrics.stats();
}
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 long compilations;
private final long cacheEvictions;
private final long compilationLimitTriggered;
private final String contextName;

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

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

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

public long getCompilations() {
return compilations;
}

public long getCacheEvictions() {
return cacheEvictions;
}

public long getCompilationLimitTriggered() {
return compilationLimitTriggered;
}

public String getContextName() {
return contextName;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(Fields.CONTEXT, getContextName());
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 contextName.compareTo(o.contextName);
}

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";
}
}
15 changes: 14 additions & 1 deletion server/src/main/java/org/elasticsearch/script/ScriptMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,21 @@ public class ScriptMetrics {
final CounterMetric cacheEvictionsMetric = new CounterMetric();
final CounterMetric compilationLimitTriggered = new CounterMetric();

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

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

public void onCompilation() {
Expand Down
Loading

0 comments on commit 2963351

Please sign in to comment.