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

IGNITE-24286 Implement recording sytemViews to perfStart report #11826

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.apache.ignite.internal.util.typedef.G;
import org.junit.Test;

import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR;
import static org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsTask.STATUS_DISABLED;
import static org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsTask.STATUS_ENABLED;
import static org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW;
import static org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.TIMEOUT;
import static org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.cleanPerformanceStatisticsDir;
import static org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.statisticsFiles;
Expand All @@ -45,6 +47,12 @@ public class PerformanceStatisticsCommandTest extends GridCommandHandlerClusterB
/** */
public static final String STATUS = "status";

/** */
public static final String ALL_VIEWS = "--all-system-views";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need to provide options here? Why just collecting all views is not a default behavior?


/** */
public static final String VIEWS = "--system-views";

/** */
public static final String PERFORMANCE_STATISTICS = "--performance-statistics";

Expand Down Expand Up @@ -150,4 +158,21 @@ public void testStopAlreadyStopped() {

assertEquals(EXIT_CODE_OK, res);
}

/** */
@Test
public void testSystemViews() {
int res = execute(PERFORMANCE_STATISTICS, START, VIEWS);

assertEquals(EXIT_CODE_INVALID_ARGUMENTS, res);

res = execute(PERFORMANCE_STATISTICS, START, ALL_VIEWS);
assertEquals(EXIT_CODE_OK, res);

res = execute(PERFORMANCE_STATISTICS, STOP);
assertEquals(EXIT_CODE_OK, res);

res = execute(PERFORMANCE_STATISTICS, START, VIEWS, CACHES_VIEW);
assertEquals(EXIT_CODE_OK, res);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package org.apache.ignite.internal.management.performancestatistics;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
import org.apache.ignite.internal.management.api.Argument;
import org.apache.ignite.internal.management.api.CommandRegistryImpl;
import org.apache.ignite.internal.util.typedef.internal.U;

/** Command to manage performance statistics. */
public class PerformanceStatisticsCommand extends CommandRegistryImpl {
Expand All @@ -38,6 +41,54 @@ public PerformanceStatisticsCommand() {
public static class PerformanceStatisticsStartCommandArg extends PerformanceStatisticsStatusCommandArg {
/** */
private static final long serialVersionUID = 0;

/** System views to get content from. */
@Argument(
optional = true,
description = "Comma-separated list of the system view names which should be collected. " +
" Both \"SQL\" and \"Java\" styles of system view name are supported" +
" (e.g. SQL_TABLES and sql.tables will be handled similarly)",
example = "view1,view2,.."
)
private String[] systemViews;

/** */
@Argument(description = "Collect all registered system views", optional = true)
private boolean allSystemViews;


/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
U.writeArray(out, systemViews);
out.writeBoolean(allSystemViews);
}

/** {@inheritDoc} */
@Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException {
systemViews = U.readArray(in, String.class);
allSystemViews = in.readBoolean();
}

/** */
public String[] systemViews() {
return systemViews;
}

/** */
public void systemViews(String[] systemViews) {
this.systemViews = systemViews;
}

/** */
public boolean allSystemViews() {
return allSystemViews;
}

/** */
public void allSystemViews(boolean allSystemViews) {
this.allSystemViews = allSystemViews;
}

}

/** */
Expand All @@ -58,12 +109,12 @@ public static class PerformanceStatisticsStatusCommandArg extends IgniteDataTran
private static final long serialVersionUID = 0;

/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) {
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
// No-op.
}

/** {@inheritDoc} */
@Override protected void readExternalData(byte protoVer, ObjectInput in) {
@Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException {
// No-op.
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@

package org.apache.ignite.internal.management.performancestatistics;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
import org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsCommand.PerformanceStatisticsRotateCommandArg;
import org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsCommand.PerformanceStatisticsStartCommandArg;
import org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsCommand.PerformanceStatisticsStatusCommandArg;
import org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsCommand.PerformanceStatisticsStopCommandArg;
import org.apache.ignite.internal.managers.systemview.GridSystemViewManager;
import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor;
import org.apache.ignite.internal.processors.task.GridInternal;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.internal.visor.VisorJob;
Expand Down Expand Up @@ -65,7 +70,22 @@ protected PerformanceStatisticsJob(IgniteDataTransferObject arg, boolean debug)
@Override protected String run(IgniteDataTransferObject arg) throws IgniteException {
try {
if (arg instanceof PerformanceStatisticsStartCommandArg) {
ignite.context().performanceStatistics().startCollectStatistics();
PerformanceStatisticsStartCommandArg startCmdArg = (PerformanceStatisticsStartCommandArg)arg;

PerformanceStatisticsProcessor performanceStatisticsProc = ignite.context().performanceStatistics();
GridSystemViewManager sysViewMgr = ignite.context().systemView();

List<String> views;

if (startCmdArg.allSystemViews()) {
views = new ArrayList<>();
sysViewMgr.forEach(view -> views.add(view.name()));
}
else if (startCmdArg.systemViews() != null) views = List.of(startCmdArg.systemViews());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block of code after condition should be on own line

else views = Collections.emptyList();

performanceStatisticsProc.addSystemViews(views);
performanceStatisticsProc.startCollectStatistics();

return "Started.";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.ignite.internal.managers.systemview.GridSystemViewManager;
import org.apache.ignite.internal.processors.metric.GridMetricManager;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.metric.MetricRegistry;
import org.apache.ignite.spi.metric.HistogramMetric;
import org.apache.ignite.spi.systemview.view.SystemView;
import org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX;
import static org.apache.ignite.internal.processors.cache.CacheMetricsImpl.CACHE_METRICS;
Expand Down Expand Up @@ -234,4 +236,29 @@ public static Map<String, Class<?>> systemViewAttributes(SystemView<?> sysView)

return attrs;
}

/**
* Extract system view from systemViewManager. Both "SQL" and "Java" styles of system view name are supported.
*
* @param systemViewManager Manager to extract view from.
* @param viewName System view name.
* @return System view with viewName. Null if the view does not exist.
*/
@Nullable public static SystemView<?> getSystemViewByName(GridSystemViewManager systemViewManager, String viewName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use prefixes like get, set, is in function names within internal packages

SystemView<?> view = systemViewManager.view(viewName);
if (view != null)
return view;

if (view == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this line view is always null.

for (SystemView<?> sysView : systemViewManager) {
if (toSqlName(sysView.name()).equalsIgnoreCase(viewName)) {
view = sysView;

break;
}
}
}

return view;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.ignite.internal.processors.performancestatistics;

import java.util.Map;
import java.util.Objects;
import org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker;
import org.jetbrains.annotations.Nullable;

/** Fullfill {@code data} Map for specific row. */
class AttributeToMapVisitor implements SystemViewRowAttributeWalker.AttributeWithValueVisitor {
/** Map to store data. */
private Map<String, String> data;

/**
* Sets map.
*
* @param data Map to fill.
*/
public void data(Map<String, String> data) {
this.data = data;
}

/** {@inheritDoc} */
@Override public <T> void accept(int idx, String name, Class<T> clazz, @Nullable T val) {
data.put(name, Objects.toString(val));
}

/** {@inheritDoc} */
@Override public void acceptBoolean(int idx, String name, boolean val) {
data.put(name, String.valueOf(val));
}

/** {@inheritDoc} */
@Override public void acceptChar(int idx, String name, char val) {
data.put(name, String.valueOf(val));
}

/** {@inheritDoc} */
@Override public void acceptByte(int idx, String name, byte val) {
data.put(name, String.valueOf(val));
}

/** {@inheritDoc} */
@Override public void acceptShort(int idx, String name, short val) {
data.put(name, String.valueOf(val));
}

/** {@inheritDoc} */
@Override public void acceptInt(int idx, String name, int val) {
data.put(name, String.valueOf(val));
}

/** {@inheritDoc} */
@Override public void acceptLong(int idx, String name, long val) {
data.put(name, String.valueOf(val));
}

/** {@inheritDoc} */
@Override public void acceptFloat(int idx, String name, float val) {
data.put(name, String.valueOf(val));
}

/** {@inheritDoc} */
@Override public void acceptDouble(int idx, String name, double val) {
data.put(name, String.valueOf(val));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY_PROPERTY;
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY_READS;
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY_ROWS;
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.SYSYTEM_VIEW;
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TASK;
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TX_COMMIT;
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.cacheOperation;
Expand Down Expand Up @@ -292,6 +293,33 @@ else if (opType == QUERY) {

return true;
}
else if (opType == SYSYTEM_VIEW) {
String viewName = readCacheableString(buf);
if (viewName == null)
return false;

if (buf.remaining() < 4)
return false;
int attrsNumber = buf.getInt();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add NL before


Map<String, String> data = new HashMap<>();
for (int i = 0; i < attrsNumber; i++) {
String key = readCacheableString(buf);
if (key == null)
return false;

String val = readCacheableString(buf);
if (val == null)
return false;

data.put(key, val);
}

for (PerformanceStatisticsHandler hnd : curHnd)
hnd.systemView(nodeId, viewName, data);

return true;
}
else if (opType == QUERY_READS) {
if (buf.remaining() < queryReadsRecordSize())
return false;
Expand Down
Loading