Skip to content

Commit

Permalink
server: Bug 579456: trace-server: use time range in TSP queries
Browse files Browse the repository at this point in the history
In queries that require sampling of timestamps, replace the large
requested_times array with a requested_timerange object.

The timestamp array is then computed in the trace server.

For the tree endpoint, replace requested_times array of [start, end]
with a requested_timerange object with no nbTimes.

For backward compatibility, the computed array is then put in the query
parameters as the requested_times, overwriting it if present.

Change-Id: I4549118df6d0b298bdc8f72dbbee8a7aa3a5f8d7
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/191752
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
PatrickTasse committed Apr 5, 2022
1 parent 40e26bc commit 9a1071a
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 34 deletions.
Expand Up @@ -75,6 +75,7 @@ public class DataProviderServiceTest extends RestServerTest {
private static final String CALL_STACK_DATAPROVIDER_ID = "org.eclipse.tracecompass.internal.analysis.profiling.callstack.provider.CallStackDataProvider";
private static final String XY_DATAPROVIDER_ID = "org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageDataProvider";
private static final String EVENTS_TABLE_DATAPROVIDER_ID = "org.eclipse.tracecompass.internal.provisional.tmf.core.model.events.TmfEventTableDataProvider";
private static final String REQUESTED_TIMERANGE_KEY = "requested_timerange";
private static final String REQUESTED_TIMES_KEY = "requested_times";
private static final String REQUESTED_ITEMS_KEY = "requested_items";
private static final String REQUESTED_ELEMENT_KEY = "requested_element";
Expand All @@ -89,6 +90,9 @@ public class DataProviderServiceTest extends RestServerTest {
private static final String DURATION = "duration";
private static final String ENTRY_ID = "entryId";
private static final String DESTINATION_ID = "destinationId";
private static final String START = "start";
private static final String END = "end";
private static final String NB_TIMES = "nbTimes";
private static final long TABLE_INDEX = 0L;
private static final long TABLE_COUNT = 100L;

Expand Down Expand Up @@ -192,6 +196,8 @@ public void testXYDataProvider() throws InterruptedException {
for (EntryStub entry : entries) {
items.add(entry.getId());
}
parameters.remove(REQUESTED_TIMES_KEY);
parameters.put(REQUESTED_TIMERANGE_KEY, ImmutableMap.of(START, start, END, end, NB_TIMES, 10));
parameters.put(REQUESTED_ITEMS_KEY, items);
Response series = xySeriesEnpoint.request().post(Entity.json(new QueryParameters(parameters, Collections.emptyList())));
assertEquals("There should be a positive response for the data provider", 200, series.getStatus());
Expand Down Expand Up @@ -264,7 +270,8 @@ public void testTimeGraphDataProvider() throws InterruptedException {

// Test getting the time graph row data
WebTarget tgStatesEnpoint = getTimeGraphStatesEndpoint(exp.getUUID().toString(), CALL_STACK_DATAPROVIDER_ID);
parameters.put(REQUESTED_TIMES_KEY, ImmutableList.of(1450193697034689597L, 1450193697118480368L));
parameters.remove(REQUESTED_TIMES_KEY);
parameters.put(REQUESTED_TIMERANGE_KEY, ImmutableMap.of(START, 1450193697034689597L, END, 1450193697118480368L, NB_TIMES, 10));
parameters.put(REQUESTED_ITEMS_KEY, items);
Response statesResponse = tgStatesEnpoint.request().post(Entity.json(new QueryParameters(parameters, Collections.emptyList())));
assertEquals("There should be a positive response for the data provider", 200, statesResponse.getStatus());
Expand Down
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2021 Ericsson
* Copyright (c) 2021, 2022 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -34,9 +34,9 @@ public interface AnnotationsQueryParameters {
*/
interface AnnotationsParameters {

@JsonProperty("requested_times")
@JsonProperty("requested_timerange")
@Schema(required = true)
long[] getRequestedTimes();
TimeRange getRequestedTimeRange();

@JsonProperty("requested_items")
int[] getRequestedItems();
Expand Down
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2021 Ericsson
* Copyright (c) 2021, 2022 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -34,8 +34,8 @@ public interface ArrowsQueryParameters {
*/
interface ArrowsParameters {

@JsonProperty("requested_times")
@JsonProperty("requested_timerange")
@Schema(required = true)
long[] getRequestedTimes();
TimeRange getRequestedTimeRange();
}
}
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2021 Ericsson
* Copyright (c) 2021, 2022 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -34,9 +34,9 @@ public interface RequestedQueryParameters {
*/
interface RequestedParameters {

@JsonProperty("requested_times")
@JsonProperty("requested_timerange")
@Schema(required = true)
long[] getRequestedTimes();
TimeRange getRequestedTimeRange();

@JsonProperty("requested_items")
@Schema(required = true)
Expand Down
@@ -0,0 +1,39 @@
/**********************************************************************
* Copyright (c) 2022 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* Contributes to the model used for TSP swagger-core annotations.
*/
@Schema(description = "A time range with optional number of timestamps to be sampled")
public interface TimeRange {

/**
* @return The start time.
*/
@Schema(description = "The start of the time range", required = true)
long getStart();

/**
* @return The end time.
*/
@Schema(description = "The end of the time range", required = true)
long getEnd();

/**
* @return The number of times to be sampled.
*/
@Schema(description = "The number of timestamps to be sampled (1-65536) in the given range", required = false)
int getNbTimes();
}
Expand Up @@ -56,11 +56,11 @@
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TABLE_TIMES;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TERMS;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TGR;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMES;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMES_EX;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMES_EX_TREE;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMERANGE;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMERANGE_EX;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMERANGE_EX_TREE;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMERANGE_TREE;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMES_EX_TT;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMES_TREE;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TIMES_TT;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TITLE;
import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.TRA;
Expand Down Expand Up @@ -308,8 +308,8 @@ public Response getProvider(
public Response getXYTree(
@Parameter(description = EXP_UUID) @PathParam("expUUID") UUID expUUID,
@Parameter(description = OUTPUT_ID) @PathParam("outputId") String outputId,
@RequestBody(description = "Query parameters to fetch the XY tree. " + TIMES_TREE, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMES_EX_TREE +
@RequestBody(description = "Query parameters to fetch the XY tree. " + TIMERANGE_TREE, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMERANGE_EX_TREE +
"}}"), schema = @Schema(implementation = TreeQueryParameters.class))
}, required = true) QueryParameters queryParameters) {
return getTree(expUUID, outputId, queryParameters);
Expand Down Expand Up @@ -341,8 +341,8 @@ public Response getXYTree(
public Response getXY(
@Parameter(description = EXP_UUID) @PathParam("expUUID") UUID expUUID,
@Parameter(description = OUTPUT_ID) @PathParam("outputId") String outputId,
@RequestBody(description = "Query parameters to fetch the XY model. " + TIMES + " " + ITEMS_XY, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMES_EX + "," + ITEMS_EX +
@RequestBody(description = "Query parameters to fetch the XY model. " + TIMERANGE + " " + ITEMS_XY, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMERANGE_EX + "," + ITEMS_EX +
"}}"), schema = @Schema(implementation = RequestedQueryParameters.class))
}, required = true) QueryParameters queryParameters) {

Expand Down Expand Up @@ -437,8 +437,8 @@ public Response getXYTooltip(@PathParam("expUUID") UUID expUUID,
public Response getTimeGraphTree(
@Parameter(description = EXP_UUID) @PathParam("expUUID") UUID expUUID,
@Parameter(description = OUTPUT_ID) @PathParam("outputId") String outputId,
@RequestBody(description = "Query parameters to fetch the timegraph tree. " + TIMES_TREE, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMES_EX_TREE +
@RequestBody(description = "Query parameters to fetch the timegraph tree. " + TIMERANGE_TREE, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMERANGE_EX_TREE +
"}}"), schema = @Schema(implementation = TreeQueryParameters.class))
}, required = true) QueryParameters queryParameters) {
return getTree(expUUID, outputId, queryParameters);
Expand Down Expand Up @@ -470,8 +470,8 @@ public Response getTimeGraphTree(
public Response getStates(
@Parameter(description = EXP_UUID) @PathParam("expUUID") UUID expUUID,
@Parameter(description = OUTPUT_ID) @PathParam("outputId") String outputId,
@RequestBody(description = "Query parameters to fetch the timegraph states. " + TIMES + " " + ITEMS, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMES_EX + "," + ITEMS_EX +
@RequestBody(description = "Query parameters to fetch the timegraph states. " + TIMERANGE + " " + ITEMS, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMERANGE_EX + "," + ITEMS_EX +
"}}"), schema = @Schema(implementation = RequestedQueryParameters.class))
}, required = true) QueryParameters queryParameters) {

Expand Down Expand Up @@ -530,8 +530,8 @@ public Response getStates(
public Response getArrows(
@Parameter(description = EXP_UUID) @PathParam("expUUID") UUID expUUID,
@Parameter(description = OUTPUT_ID) @PathParam("outputId") String outputId,
@RequestBody(description = "Query parameters to fetch the timegraph arrows. " + TIMES, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMES_EX +
@RequestBody(description = "Query parameters to fetch the timegraph arrows. " + TIMERANGE, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" + TIMERANGE_EX +
"}}"), schema = @Schema(implementation = ArrowsQueryParameters.class))
}, required = true) QueryParameters queryParameters) {

Expand Down Expand Up @@ -692,9 +692,9 @@ public Response getAnnotations(
@Parameter(description = EXP_UUID) @PathParam("expUUID") UUID expUUID,
@Parameter(description = OUTPUT_ID) @PathParam("outputId") String outputId,
@RequestBody(description = "Query parameters to fetch the annotations. " +
TIMES + " " + ITEMS + " " + MARKER_SET + MARKER_CATEGORIES, content = {
TIMERANGE + " " + ITEMS + " " + MARKER_SET + MARKER_CATEGORIES, content = {
@Content(examples = @ExampleObject("{\"parameters\":{" +
TIMES_EX + "," + ITEMS_EX + "," + MARKER_SET_EX + MARKER_CATEGORIES_EX +
TIMERANGE_EX + "," + ITEMS_EX + "," + MARKER_SET_EX + MARKER_CATEGORIES_EX +
"}}"), schema = @Schema(implementation = AnnotationsQueryParameters.class))
}, required = true) QueryParameters queryParameters) {

Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Ericsson
* Copyright (c) 2021, 2022 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -44,6 +44,8 @@ public class EndpointConstants {
/** Error message returned for a request with missing output Id */
public static final String MISSING_OUTPUTID = "Missing parameter outputId"; //$NON-NLS-1$

/** Query parameter key for requested time range */
private static final String REQUESTED_TIMERANGE_KEY = "requested_timerange"; //$NON-NLS-1$
/**
* Swagger constants redefined out of TmfEventTableDataProvider non-API
* restriction. This is unlike constants in DataProviderParameterUtils.
Expand Down Expand Up @@ -109,8 +111,8 @@ public class EndpointConstants {
static final String MARKER_SET = "The string '" + REQUESTED_MARKER_SET_KEY + "' is the optional requested marker set's id. "; //$NON-NLS-1$ //$NON-NLS-2$
static final String ONE_OF = "One of '" + REQUESTED_TABLE_INDEX_KEY + "' or '" + REQUESTED_TIME_KEY + "' should be present. "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
static final String TABLE_TIMES = "If '" + REQUESTED_TIME_KEY + "' is used it should contain an array with a single timestamp. The returned lines starting at the given timestamp (or the nearest following) will be returned. "; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMES = "The array '" + REQUESTED_TIME_KEY + "' is the explicit array of requested sample times."; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMES_TREE = "When '" + REQUESTED_TIME_KEY + "' is absent the tree for the full range is returned. When present it specifies a range as [start, end]."; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMERANGE = "The object '" + REQUESTED_TIMERANGE_KEY + "' is the requested time range and number of samples."; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMERANGE_TREE = "The object '" + REQUESTED_TIMERANGE_KEY + "' specifies the requested time range. When absent the tree for the full range is returned."; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMES_TT = "The array '" + REQUESTED_TIME_KEY + "' is an array with a single timestamp. "; //$NON-NLS-1$ //$NON-NLS-2$

/**
Expand All @@ -127,8 +129,8 @@ public class EndpointConstants {
static final String ITEMS_EX_TT = "\"" + REQUESTED_ITEMS_KEY + "\": [1],"; //$NON-NLS-1$ //$NON-NLS-2$
static final String MARKER_CATEGORIES_EX = "\"" + REQUESTED_MARKER_CATEGORIES_KEY + "\": [\"category1\", \"category2\"]"; //$NON-NLS-1$ //$NON-NLS-2$
static final String MARKER_SET_EX = "\"" + REQUESTED_MARKER_SET_KEY + "\": \"markerSetId\","; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMES_EX = "\"" + REQUESTED_TIME_KEY + "\": [111200000, 111300000, 111400000, 111500000]"; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMES_EX_TREE = "\"" + REQUESTED_TIME_KEY + "\": [111111111, 222222222]"; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMERANGE_EX = "\"" + REQUESTED_TIME_KEY + "\": {\"start\": 111111111, \"end\": 222222222, \"nbTimes\": 1920}"; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMERANGE_EX_TREE = "\"" + REQUESTED_TIME_KEY + "\": {\"start\": 111111111, \"end\": 222222222}"; //$NON-NLS-1$ //$NON-NLS-2$
static final String TIMES_EX_TT = "\"" + REQUESTED_TIME_KEY + "\": [111200000],"; //$NON-NLS-1$ //$NON-NLS-2$

/** Swagger @ApiResponse description constants reused, or centralized. */
Expand Down

0 comments on commit 9a1071a

Please sign in to comment.