77import com .azure .core .annotation .ServiceClient ;
88import com .azure .core .annotation .ServiceMethod ;
99import com .azure .core .exception .HttpResponseException ;
10+ import com .azure .core .exception .ServiceResponseException ;
1011import com .azure .core .experimental .models .HttpResponseError ;
11- import com .azure .core .experimental .models .TimeInterval ;
1212import com .azure .core .http .rest .Response ;
1313import com .azure .core .http .rest .SimpleResponse ;
1414import com .azure .core .util .BinaryData ;
3131import com .azure .monitor .query .models .LogsBatchQueryResultCollection ;
3232import com .azure .monitor .query .models .LogsQueryOptions ;
3333import com .azure .monitor .query .models .LogsQueryResult ;
34+ import com .azure .monitor .query .models .LogsQueryResultStatus ;
3435import com .azure .monitor .query .models .LogsTable ;
3536import com .azure .monitor .query .models .LogsTableCell ;
3637import com .azure .monitor .query .models .LogsTableColumn ;
3738import com .azure .monitor .query .models .LogsTableRow ;
39+ import com .azure .monitor .query .models .QueryTimeInterval ;
3840import reactor .core .publisher .Mono ;
41+ import reactor .core .publisher .SynchronousSink ;
3942
4043import java .time .Duration ;
4144import java .util .ArrayList ;
@@ -69,15 +72,15 @@ public final class LogsQueryAsyncClient {
6972 * Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
7073 *
7174 * <p><strong>Query logs from the last 24 hours</strong></p>
72- * {@codesnippet com.azure.monitor.query.LogsQueryAsyncClient.query#String-String-TimeInterval }
75+ * {@codesnippet com.azure.monitor.query.LogsQueryAsyncClient.query#String-String-QueryTimeInterval }
7376 *
7477 * @param workspaceId The workspaceId where the query should be executed.
7578 * @param query The Kusto query to fetch the logs.
7679 * @param timeInterval The time period for which the logs should be looked up.
7780 * @return The logs matching the query.
7881 */
7982 @ ServiceMethod (returns = ReturnType .SINGLE )
80- public Mono <LogsQueryResult > query (String workspaceId , String query , TimeInterval timeInterval ) {
83+ public Mono <LogsQueryResult > query (String workspaceId , String query , QueryTimeInterval timeInterval ) {
8184 return queryWithResponse (workspaceId , query , timeInterval , new LogsQueryOptions ())
8285 .map (Response ::getValue );
8386 }
@@ -92,7 +95,7 @@ public Mono<LogsQueryResult> query(String workspaceId, String query, TimeInterva
9295 * @return The logs matching the query as a list of objects of type T.
9396 */
9497 @ ServiceMethod (returns = ReturnType .SINGLE )
95- public <T > Mono <List <T >> query (String workspaceId , String query , TimeInterval timeInterval , Class <T > type ) {
98+ public <T > Mono <List <T >> query (String workspaceId , String query , QueryTimeInterval timeInterval , Class <T > type ) {
9699 return query (workspaceId , query , timeInterval )
97100 .map (result -> LogsQueryHelper .toObject (result .getTable (), type ));
98101 }
@@ -108,7 +111,7 @@ public <T> Mono<List<T>> query(String workspaceId, String query, TimeInterval ti
108111 * @return The logs matching the query as a list of objects of type T.
109112 */
110113 @ ServiceMethod (returns = ReturnType .SINGLE )
111- public <T > Mono <List <T >> query (String workspaceId , String query , TimeInterval timeInterval ,
114+ public <T > Mono <List <T >> query (String workspaceId , String query , QueryTimeInterval timeInterval ,
112115 Class <T > type , LogsQueryOptions options ) {
113116 return queryWithResponse (workspaceId , query , timeInterval , options , Context .NONE )
114117 .map (response -> LogsQueryHelper .toObject (response .getValue ().getTable (), type ));
@@ -119,7 +122,7 @@ public <T> Mono<List<T>> query(String workspaceId, String query, TimeInterval ti
119122 *
120123 * <p><strong>Query logs from the last 7 days and set the service timeout to 2 minutes</strong></p>
121124 *
122- * {@codesnippet com.azure.monitor.query.LogsQueryAsyncClient.queryWithResponse#String-String-TimeInterval -LogsQueryOptions}
125+ * {@codesnippet com.azure.monitor.query.LogsQueryAsyncClient.queryWithResponse#String-String-QueryTimeInterval -LogsQueryOptions}
123126 *
124127 * @param workspaceId The workspaceId where the query should be executed.
125128 * @param query The Kusto query to fetch the logs.
@@ -130,7 +133,7 @@ public <T> Mono<List<T>> query(String workspaceId, String query, TimeInterval ti
130133 */
131134 @ ServiceMethod (returns = ReturnType .SINGLE )
132135 public Mono <Response <LogsQueryResult >> queryWithResponse (String workspaceId , String query ,
133- TimeInterval timeInterval , LogsQueryOptions options ) {
136+ QueryTimeInterval timeInterval , LogsQueryOptions options ) {
134137 return withContext (context -> queryWithResponse (workspaceId , query , timeInterval , options , context ));
135138 }
136139
@@ -147,7 +150,7 @@ public Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, Str
147150 * @return The logs matching the query including the HTTP response.
148151 */
149152 @ ServiceMethod (returns = ReturnType .SINGLE )
150- public <T > Mono <Response <List <T >>> queryWithResponse (String workspaceId , String query , TimeInterval timeInterval ,
153+ public <T > Mono <Response <List <T >>> queryWithResponse (String workspaceId , String query , QueryTimeInterval timeInterval ,
151154 Class <T > type , LogsQueryOptions options ) {
152155 return queryWithResponse (workspaceId , query , timeInterval , options )
153156 .map (response -> new SimpleResponse <>(response .getRequest (),
@@ -164,7 +167,7 @@ public <T> Mono<Response<List<T>>> queryWithResponse(String workspaceId, String
164167 * @return A collection of query results corresponding to the input batch of queries.
165168 */
166169 Mono <LogsBatchQueryResultCollection > queryBatch (String workspaceId , List <String > queries ,
167- TimeInterval timeInterval ) {
170+ QueryTimeInterval timeInterval ) {
168171 LogsBatchQuery logsBatchQuery = new LogsBatchQuery ();
169172 queries .forEach (query -> logsBatchQuery .addQuery (workspaceId , query , timeInterval ));
170173 return queryBatchWithResponse (logsBatchQuery ).map (Response ::getValue );
@@ -263,14 +266,14 @@ private HttpResponseError mapLogsQueryError(ErrorInfo errors) {
263266 return null ;
264267 }
265268
266- Mono <Response <LogsQueryResult >> queryWithResponse (String workspaceId , String query , TimeInterval timeInterval ,
269+ Mono <Response <LogsQueryResult >> queryWithResponse (String workspaceId , String query , QueryTimeInterval timeInterval ,
267270 LogsQueryOptions options , Context context ) {
268271 String preferHeader = LogsQueryHelper .buildPreferHeaderString (options );
269272 context = updateContext (options .getServerTimeout (), context );
270273
271274 QueryBody queryBody = new QueryBody (query );
272275 if (timeInterval != null ) {
273- queryBody .setTimespan (timeInterval .toIso8601Format ());
276+ queryBody .setTimespan (LogsQueryHelper .toIso8601Format (timeInterval ));
274277 }
275278 queryBody .setWorkspaces (getAllWorkspaces (options ));
276279 return innerClient
@@ -288,7 +291,16 @@ Mono<Response<LogsQueryResult>> queryWithResponse(String workspaceId, String que
288291 }
289292 return ex ;
290293 })
291- .map (this ::convertToLogQueryResult );
294+ .map (this ::convertToLogQueryResult )
295+ .handle ((Response <LogsQueryResult > response , SynchronousSink <Response <LogsQueryResult >> sink ) -> {
296+ if (response .getValue ().getQueryResultStatus () == LogsQueryResultStatus .PARTIAL_FAILURE ) {
297+ sink .error (new ServiceResponseException ("Query execution returned partial errors. To "
298+ + "disable exceptions on partial errors, set disableExceptionOnPartialErrors in "
299+ + "LogsQueryOptions to true." ));
300+ } else {
301+ sink .next (response );
302+ }
303+ });
292304 }
293305
294306 private Response <LogsQueryResult > convertToLogQueryResult (Response <QueryResults > response ) {
0 commit comments