Skip to content

Commit f82f87a

Browse files
authored
[6.8] Slow log must use separate underlying logger for each index BACKPORT(#47234) (#48177)
* Slow log must use separate underlying logger for each index (#47234) SlowLog instances should not share the same underlying logger, as it would cause different indexes override each other levels. When creating underlying logger, unique per index identifier should be used. Name + IndexSettings.UUID Closes #42432
1 parent 11f0c99 commit f82f87a

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public final class IndexingSlowLog implements IndexingOperationListener {
5252
*/
5353
private int maxSourceCharsToLog;
5454

55-
private SlowLogLevel level;
56-
5755
private final Logger indexLogger;
5856

5957
private static final String INDEX_INDEXING_SLOWLOG_PREFIX = "index.indexing.slowlog";
@@ -90,7 +88,7 @@ public final class IndexingSlowLog implements IndexingOperationListener {
9088
}, Property.Dynamic, Property.IndexScope);
9189

9290
IndexingSlowLog(IndexSettings indexSettings) {
93-
this.indexLogger = LogManager.getLogger(INDEX_INDEXING_SLOWLOG_PREFIX + ".index");
91+
this.indexLogger = LogManager.getLogger(INDEX_INDEXING_SLOWLOG_PREFIX + ".index." + indexSettings.getUUID());
9492
this.index = indexSettings.getIndex();
9593

9694
indexSettings.getScopedSettings().addSettingsUpdateConsumer(INDEX_INDEXING_SLOWLOG_REFORMAT_SETTING, this::setReformat);
@@ -119,7 +117,6 @@ private void setMaxSourceCharsToLog(int maxSourceCharsToLog) {
119117
}
120118

121119
private void setLevel(SlowLogLevel level) {
122-
this.level = level;
123120
Loggers.setLevel(this.indexLogger, level.name());
124121
}
125122

@@ -233,7 +230,7 @@ int getMaxSourceCharsToLog() {
233230
}
234231

235232
SlowLogLevel getLevel() {
236-
return level;
233+
return SlowLogLevel.parse(indexLogger.getLevel().name());
237234
}
238235

239236
}

server/src/main/java/org/elasticsearch/index/SearchSlowLog.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public final class SearchSlowLog implements SearchOperationListener {
4545
private long fetchDebugThreshold;
4646
private long fetchTraceThreshold;
4747

48-
private SlowLogLevel level;
49-
5048
private final Logger queryLogger;
5149
private final Logger fetchLogger;
5250

@@ -83,8 +81,8 @@ public final class SearchSlowLog implements SearchOperationListener {
8381

8482
public SearchSlowLog(IndexSettings indexSettings) {
8583

86-
this.queryLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query");
87-
this.fetchLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch");
84+
this.queryLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query." + indexSettings.getUUID());
85+
this.fetchLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch." + indexSettings.getUUID());
8886

8987
indexSettings.getScopedSettings().addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING,
9088
this::setQueryWarnThreshold);
@@ -117,7 +115,6 @@ public SearchSlowLog(IndexSettings indexSettings) {
117115
}
118116

119117
private void setLevel(SlowLogLevel level) {
120-
this.level = level;
121118
Loggers.setLevel(queryLogger, level.name());
122119
Loggers.setLevel(fetchLogger, level.name());
123120
}
@@ -259,6 +256,7 @@ long getFetchTraceThreshold() {
259256
}
260257

261258
SlowLogLevel getLevel() {
262-
return level;
259+
assert queryLogger.getLevel().equals(fetchLogger.getLevel());
260+
return SlowLogLevel.parse(queryLogger.getLevel().name());
263261
}
264262
}

server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.lucene.document.NumericDocValuesField;
2424
import org.elasticsearch.Version;
2525
import org.elasticsearch.cluster.metadata.IndexMetaData;
26+
import org.elasticsearch.common.UUIDs;
2627
import org.elasticsearch.common.bytes.BytesArray;
2728
import org.elasticsearch.common.bytes.BytesReference;
2829
import org.elasticsearch.common.settings.Settings;
@@ -189,6 +190,25 @@ public void testLevelSetting() {
189190
assertThat(cause, hasToString(containsString("No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL")));
190191
}
191192
assertEquals(SlowLogLevel.TRACE, log.getLevel());
193+
194+
metaData = newIndexMeta("index", Settings.builder()
195+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
196+
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
197+
.put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), SlowLogLevel.DEBUG)
198+
.build());
199+
settings = new IndexSettings(metaData, Settings.EMPTY);
200+
IndexingSlowLog debugLog = new IndexingSlowLog(settings);
201+
202+
metaData = newIndexMeta("index", Settings.builder()
203+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
204+
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
205+
.put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), SlowLogLevel.INFO)
206+
.build());
207+
settings = new IndexSettings(metaData, Settings.EMPTY);
208+
IndexingSlowLog infoLog = new IndexingSlowLog(settings);
209+
210+
assertEquals(SlowLogLevel.DEBUG, debugLog.getLevel());
211+
assertEquals(SlowLogLevel.INFO, infoLog.getLevel());
192212
}
193213

194214
public void testSetLevels() {

server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* software distributed under the License is distributed on an
1414
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1515
* KIND, either express or implied. See the License for the
16-
* specific language governing permissions and limitations
16+
git status * specific language governing permissions and limitations
1717
* under the License.
1818
*/
1919

@@ -23,6 +23,7 @@
2323
import org.elasticsearch.action.search.SearchTask;
2424
import org.elasticsearch.action.search.SearchType;
2525
import org.elasticsearch.cluster.metadata.IndexMetaData;
26+
import org.elasticsearch.common.UUIDs;
2627
import org.elasticsearch.common.bytes.BytesReference;
2728
import org.elasticsearch.common.settings.Settings;
2829
import org.elasticsearch.common.unit.TimeValue;
@@ -223,6 +224,25 @@ public void testLevelSetting() {
223224
assertThat(cause, hasToString(containsString("No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL")));
224225
}
225226
assertEquals(SlowLogLevel.TRACE, log.getLevel());
227+
228+
metaData = newIndexMeta("index", Settings.builder()
229+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
230+
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
231+
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), SlowLogLevel.DEBUG)
232+
.build());
233+
settings = new IndexSettings(metaData, Settings.EMPTY);
234+
SearchSlowLog debugLog = new SearchSlowLog(settings);
235+
236+
metaData = newIndexMeta("index", Settings.builder()
237+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
238+
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
239+
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), SlowLogLevel.INFO)
240+
.build());
241+
settings = new IndexSettings(metaData, Settings.EMPTY);
242+
SearchSlowLog infoLog = new SearchSlowLog(settings);
243+
244+
assertEquals(SlowLogLevel.DEBUG, debugLog.getLevel());
245+
assertEquals(SlowLogLevel.INFO, infoLog.getLevel());
226246
}
227247

228248
public void testSetQueryLevels() {

0 commit comments

Comments
 (0)