
org.glowroot.storage.simplerepo.TracePointQueryBuilder Maven / Gradle / Ivy
/*
* Copyright 2013-2015 the original author or authors.
*
* Licensed 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.glowroot.storage.simplerepo;
import java.util.List;
import java.util.Locale;
import javax.annotation.Nullable;
import org.glowroot.agent.shaded.google.common.base.Strings;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.checkerframework.checker.tainting.qual.Untainted;
import org.immutables.value.Value;
import org.glowroot.common.live.LiveTraceRepository.TracePointQuery;
import org.glowroot.common.live.StringComparator;
import org.glowroot.common.util.Styles;
class TracePointQueryBuilder {
private final TracePointQuery query;
TracePointQueryBuilder(TracePointQuery query) {
this.query = query;
}
// capture time lower bound is non-inclusive so that aggregate data intervals can be mapped
// to their trace points (aggregate data intervals are non-inclusive on lower bound and
// inclusive on upper bound)
ParameterizedSql getParameterizedSql() {
ParameterizedSqlBuilder builder = new ParameterizedSqlBuilder();
builder.appendText("select trace.server_id, trace.id, trace.capture_time,"
+ " trace.duration_nanos, trace.error from trace");
ParameterizedSql criteria = getAttributeCriteria();
if (criteria == null) {
builder.appendText(" where");
} else {
builder.appendText(", trace_attribute attr where attr.server_id = trace.server_id"
+ " and attr.id = trace.id and attr.capture_time > ? and attr.capture_time <= ?"
+ " and" + criteria.sql());
builder.addArg(query.from());
builder.addArg(query.to());
builder.addArgs(criteria.args());
}
// FIXME maintain table of server_rollup/server_rollup associations and join that here
// (maintain this table on agent "Hello", wipe out prior associations and add new ones)
builder.appendText(
" trace.server_id = ? and trace.capture_time > ? and trace.capture_time <= ?");
builder.addArg(query.serverRollup());
builder.addArg(query.from());
builder.addArg(query.to());
appendTotalNanosCriteria(builder);
appendTransactionTypeCriteria(builder);
appendSlowOnlyCriteria(builder);
appendErrorOnlyCriteria(builder);
appendTransactionNameCriteria(builder);
appendHeadlineCriteria(builder);
appendErrorCriteria(builder);
appendUserCriteria(builder);
appendOrderByAndLimit(builder);
return builder.build();
}
private @Nullable ParameterizedSql getAttributeCriteria() {
String sql = "";
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy