@@ -114,6 +114,8 @@ protected void apply(MeasureQuery query) {
114114 public List <ServiceInstance > listInstances (Duration duration , String serviceId ) throws IOException {
115115 TimestampRange timestampRange = null ;
116116 if (duration != null ) {
117+ // The data time should <= endTimeBucket.
118+ // It's equals to the condition `query.and(lte(InstanceTraffic.TIME_BUCKET, endTimeBucket))`
117119 timestampRange = new TimestampRange (0 , duration .getEndTimestamp ());
118120 }
119121 MetadataRegistry .Schema schema = MetadataRegistry .INSTANCE .findMetadata (InstanceTraffic .INDEX_NAME , DownSampling .Minute );
@@ -127,8 +129,8 @@ protected void apply(MeasureQuery query) {
127129 if (StringUtil .isNotEmpty (serviceId )) {
128130 query .and (eq (InstanceTraffic .SERVICE_ID , serviceId ));
129131 }
130- final var minuteTimeBucket = TimeBucket .getMinuteTimeBucket (duration .getStartTimestamp ());
131- query .and (gte (InstanceTraffic .LAST_PING_TIME_BUCKET , minuteTimeBucket ));
132+ final var startTimeBucket = TimeBucket .getMinuteTimeBucket (duration .getStartTimestamp ());
133+ query .and (gte (InstanceTraffic .LAST_PING_TIME_BUCKET , startTimeBucket ));
132134 query .limit (limit );
133135 }
134136 });
@@ -184,9 +186,16 @@ protected void apply(MeasureQuery query) {
184186 @ Override
185187 public List <Endpoint > findEndpoint (String keyword , String serviceId , int limit , Duration duration ) throws IOException {
186188 MetadataRegistry .Schema schema = MetadataRegistry .INSTANCE .findMetadata (EndpointTraffic .INDEX_NAME , DownSampling .Minute );
189+ TimestampRange timestampRange = null ;
190+ if (duration != null ) {
191+ // The data time should <= endTimeBucket.
192+ // It's equals to the condition `query.and(lte(EndpointTraffic.TIME_BUCKET, endTimeBucket))`
193+ timestampRange = new TimestampRange (0 , duration .getEndTimestamp ());
194+ }
187195 MeasureQueryResponse resp = query (false , schema ,
188196 ENDPOINT_TRAFFIC_TAGS ,
189197 Collections .emptySet (),
198+ timestampRange ,
190199 new QueryBuilder <MeasureQuery >() {
191200 @ Override
192201 protected void apply (MeasureQuery query ) {
@@ -201,9 +210,7 @@ protected void apply(MeasureQuery query) {
201210 }
202211 if (duration != null ) {
203212 final var startTimeBucket = TimeBucket .getMinuteTimeBucket (duration .getStartTimestamp ());
204- final var endTimeBucket = TimeBucket .getMinuteTimeBucket (duration .getEndTimestamp ());
205213 query .and (gte (EndpointTraffic .LAST_PING_TIME_BUCKET , startTimeBucket ));
206- query .and (lte (EndpointTraffic .LAST_PING_TIME_BUCKET , endTimeBucket ));
207214 }
208215 query .setOrderBy (new AbstractQuery .OrderBy (AbstractQuery .Sort .DESC ));
209216 query .limit (limit );
@@ -220,19 +227,23 @@ protected void apply(MeasureQuery query) {
220227 @ Override
221228 public List <Process > listProcesses (String serviceId , ProfilingSupportStatus supportStatus , long lastPingStartTimeBucket , long lastPingEndTimeBucket ) throws IOException {
222229 MetadataRegistry .Schema schema = MetadataRegistry .INSTANCE .findMetadata (ProcessTraffic .INDEX_NAME , DownSampling .Minute );
230+ TimestampRange timestampRange = null ;
231+ if (lastPingEndTimeBucket > 0 ) {
232+ // The data time should <= endTimeBucket.
233+ // It's equals to the condition `query.and(lte(ProcessTraffic.TIME_BUCKET, endTimeBucket))`
234+ timestampRange = new TimestampRange (0 , TimeBucket .getTimestamp (lastPingEndTimeBucket ));
235+ }
223236 MeasureQueryResponse resp = query (false , schema ,
224237 PROCESS_TRAFFIC_TAGS ,
225238 Collections .emptySet (),
239+ timestampRange ,
226240 new QueryBuilder <MeasureQuery >() {
227241 @ Override
228242 protected void apply (MeasureQuery query ) {
229243 query .and (eq (ProcessTraffic .SERVICE_ID , serviceId ));
230244 if (lastPingStartTimeBucket > 0 ) {
231245 query .and (gte (ProcessTraffic .LAST_PING_TIME_BUCKET , lastPingStartTimeBucket ));
232246 }
233- if (lastPingEndTimeBucket > 0 ) {
234- query .and (lte (ProcessTraffic .LAST_PING_TIME_BUCKET , lastPingEndTimeBucket ));
235- }
236247 if (supportStatus != null ) {
237248 query .and (eq (ProcessTraffic .PROFILING_SUPPORT_STATUS , supportStatus .value ()));
238249 }
@@ -252,10 +263,17 @@ protected void apply(MeasureQuery query) {
252263 @ Override
253264 public List <Process > listProcesses (String serviceInstanceId , Duration duration , boolean includeVirtual ) throws IOException {
254265 MetadataRegistry .Schema schema = MetadataRegistry .INSTANCE .findMetadata (ProcessTraffic .INDEX_NAME , DownSampling .Minute );
266+ TimestampRange timestampRange = null ;
267+ if (duration != null ) {
268+ // The data time should <= endTimeBucket.
269+ // It's equals to the condition `query.and(lte(ProcessTraffic.TIME_BUCKET, endTimeBucket))`
270+ timestampRange = new TimestampRange (0 , duration .getEndTimestamp ());
271+ }
255272 long lastPingStartTimeBucket = duration .getStartTimeBucket ();
256273 MeasureQueryResponse resp = query (false , schema ,
257274 PROCESS_TRAFFIC_TAGS ,
258275 Collections .emptySet (),
276+ timestampRange ,
259277 new QueryBuilder <MeasureQuery >() {
260278 @ Override
261279 protected void apply (MeasureQuery query ) {
@@ -279,15 +297,21 @@ protected void apply(MeasureQuery query) {
279297 @ Override
280298 public List <Process > listProcesses (String agentId , long startPingTimeBucket , long endPingTimeBucket ) throws IOException {
281299 MetadataRegistry .Schema schema = MetadataRegistry .INSTANCE .findMetadata (ProcessTraffic .INDEX_NAME , DownSampling .Minute );
300+ TimestampRange timestampRange = null ;
301+ if (endPingTimeBucket > 0 ) {
302+ // The data time should <= endTimeBucket.
303+ // It's equals to the condition `query.and(lte(ProcessTraffic.TIME_BUCKET, endTimeBucket))`
304+ timestampRange = new TimestampRange (0 , TimeBucket .getTimestamp (endPingTimeBucket ));
305+ }
282306 MeasureQueryResponse resp = query (false , schema ,
283307 PROCESS_TRAFFIC_TAGS ,
284308 Collections .emptySet (),
309+ timestampRange ,
285310 new QueryBuilder <MeasureQuery >() {
286311 @ Override
287312 protected void apply (MeasureQuery query ) {
288313 query .and (eq (ProcessTraffic .AGENT_ID , agentId ));
289314 query .and (gte (ProcessTraffic .LAST_PING_TIME_BUCKET , startPingTimeBucket ));
290- query .and (lte (ProcessTraffic .LAST_PING_TIME_BUCKET , endPingTimeBucket ));
291315 query .and (ne (ProcessTraffic .DETECT_TYPE , ProcessDetectType .VIRTUAL .value ()));
292316 query .limit (limit );
293317 }
0 commit comments