@@ -554,6 +554,8 @@ func GetDashboardAnalytics(c *gin.Context) {
554
554
c .JSON (http .StatusBadRequest , ErrorResponse {Error : "Invalid start_date format, expected YYYY-MM-DD: " + err .Error ()})
555
555
return
556
556
}
557
+ // Convert to UTC for consistent processing
558
+ startTime = startTime .UTC ()
557
559
}
558
560
559
561
if req .EndDate != "" {
@@ -562,8 +564,8 @@ func GetDashboardAnalytics(c *gin.Context) {
562
564
c .JSON (http .StatusBadRequest , ErrorResponse {Error : "Invalid end_date format, expected YYYY-MM-DD: " + err .Error ()})
563
565
return
564
566
}
565
- // Set end time to end of day
566
- endTime = endTime .Add (23 * time .Hour + 59 * time .Minute + 59 * time .Second )
567
+ // Set end time to end of day and convert to UTC
568
+ endTime = endTime .Add (23 * time .Hour + 59 * time .Minute + 59 * time .Second ). UTC ()
567
569
}
568
570
569
571
// Set default time range if not provided (last 30 days)
@@ -578,17 +580,14 @@ func GetDashboardAnalytics(c *gin.Context) {
578
580
579
581
logger .Debugf ("Dashboard request for log_path: %s, parsed start_time: %v, end_time: %v" , req .LogPath , startTime , endTime )
580
582
581
- // For Dashboard queries, only query the specific file requested, not the entire log group
582
- // This ensures that when user clicks on a specific file, they see data only from that file
583
- logPaths := []string {req .LogPath }
584
-
585
- // Debug: Log the paths being queried
586
- logger .Debugf ("Dashboard querying specific log path: %s" , req .LogPath )
583
+ // Use main_log_path field for efficient log group queries instead of expanding file paths
584
+ // This provides much better performance by using indexed field filtering
585
+ logger .Debugf ("Dashboard querying log group with main_log_path: %s" , req .LogPath )
587
586
588
587
// Build dashboard query request
589
588
dashboardReq := & analytics.DashboardQueryRequest {
590
589
LogPath : req .LogPath ,
591
- LogPaths : logPaths ,
590
+ LogPaths : [] string { req . LogPath }, // Use single main log path
592
591
StartTime : startTime .Unix (),
593
592
EndTime : endTime .Unix (),
594
593
}
@@ -652,24 +651,20 @@ func GetWorldMapData(c *gin.Context) {
652
651
}
653
652
}
654
653
655
- // Expand log path for filtering
656
- logPaths , err := nginx_log .ExpandLogGroupPath (req .Path )
657
- if err != nil {
658
- logger .Warnf ("Could not expand log group path for world map %s: %v" , req .Path , err )
659
- logPaths = []string {req .Path } // Fallback
660
- }
661
- logger .Debugf ("WorldMapData - Expanded log paths: %v" , logPaths )
654
+ // Use main_log_path field for efficient log group queries instead of expanding file paths
655
+ logger .Debugf ("WorldMapData - Using main_log_path field for log group: %s" , req .Path )
662
656
663
657
// Get world map data with timeout
664
658
ctx , cancel := context .WithTimeout (c .Request .Context (), 30 * time .Second )
665
659
defer cancel ()
666
660
667
661
geoReq := & analytics.GeoQueryRequest {
668
- StartTime : req .StartTime ,
669
- EndTime : req .EndTime ,
670
- LogPath : req .Path ,
671
- LogPaths : logPaths ,
672
- Limit : req .Limit ,
662
+ StartTime : req .StartTime ,
663
+ EndTime : req .EndTime ,
664
+ LogPath : req .Path ,
665
+ LogPaths : []string {req .Path }, // Use single main log path
666
+ UseMainLogPath : true , // Use main_log_path field for efficient queries
667
+ Limit : req .Limit ,
673
668
}
674
669
logger .Debugf ("WorldMapData - GeoQueryRequest: %+v" , geoReq )
675
670
@@ -757,24 +752,20 @@ func GetChinaMapData(c *gin.Context) {
757
752
}
758
753
}
759
754
760
- // Expand log path for filtering
761
- logPaths , err := nginx_log .ExpandLogGroupPath (req .Path )
762
- if err != nil {
763
- logger .Warnf ("Could not expand log group path for China map %s: %v" , req .Path , err )
764
- logPaths = []string {req .Path } // Fallback
765
- }
766
- logger .Debugf ("ChinaMapData - Expanded log paths: %v" , logPaths )
755
+ // Use main_log_path field for efficient log group queries instead of expanding file paths
756
+ logger .Debugf ("ChinaMapData - Using main_log_path field for log group: %s" , req .Path )
767
757
768
758
// Get China map data with timeout
769
759
ctx , cancel := context .WithTimeout (c .Request .Context (), 30 * time .Second )
770
760
defer cancel ()
771
761
772
762
geoReq := & analytics.GeoQueryRequest {
773
- StartTime : req .StartTime ,
774
- EndTime : req .EndTime ,
775
- LogPath : req .Path ,
776
- LogPaths : logPaths ,
777
- Limit : req .Limit ,
763
+ StartTime : req .StartTime ,
764
+ EndTime : req .EndTime ,
765
+ LogPath : req .Path ,
766
+ LogPaths : []string {req .Path }, // Use single main log path
767
+ UseMainLogPath : true , // Use main_log_path field for efficient queries
768
+ Limit : req .Limit ,
778
769
}
779
770
logger .Debugf ("ChinaMapData - GeoQueryRequest: %+v" , geoReq )
780
771
@@ -855,12 +846,8 @@ func GetGeoStats(c *gin.Context) {
855
846
}
856
847
}
857
848
858
- // Expand log path for filtering
859
- logPaths , err := nginx_log .ExpandLogGroupPath (req .Path )
860
- if err != nil {
861
- logger .Warnf ("Could not expand log group path for geo stats %s: %v" , req .Path , err )
862
- logPaths = []string {req .Path } // Fallback
863
- }
849
+ // Use main_log_path field for efficient log group queries instead of expanding file paths
850
+ logger .Debugf ("GeoStats - Using main_log_path field for log group: %s" , req .Path )
864
851
865
852
// Set default limit if not provided
866
853
if req .Limit == 0 {
@@ -872,11 +859,12 @@ func GetGeoStats(c *gin.Context) {
872
859
defer cancel ()
873
860
874
861
geoReq := & analytics.GeoQueryRequest {
875
- StartTime : req .StartTime ,
876
- EndTime : req .EndTime ,
877
- LogPath : req .Path ,
878
- LogPaths : logPaths ,
879
- Limit : req .Limit ,
862
+ StartTime : req .StartTime ,
863
+ EndTime : req .EndTime ,
864
+ LogPath : req .Path ,
865
+ LogPaths : []string {req .Path }, // Use single main log path
866
+ UseMainLogPath : true , // Use main_log_path field for efficient queries
867
+ Limit : req .Limit ,
880
868
}
881
869
882
870
stats , err := analyticsService .GetTopCountries (ctx , geoReq )
@@ -902,10 +890,11 @@ func getCardinalityCount(ctx context.Context, field string, searchReq *searcher.
902
890
903
891
// Create a CardinalityRequest from the SearchRequest
904
892
cardReq := & searcher.CardinalityRequest {
905
- Field : field ,
906
- StartTime : searchReq .StartTime ,
907
- EndTime : searchReq .EndTime ,
908
- LogPaths : searchReq .LogPaths ,
893
+ Field : field ,
894
+ StartTime : searchReq .StartTime ,
895
+ EndTime : searchReq .EndTime ,
896
+ LogPaths : searchReq .LogPaths ,
897
+ UseMainLogPath : searchReq .UseMainLogPath , // Use main_log_path field if enabled
909
898
}
910
899
logger .Debugf ("🔍 CardinalityRequest: Field=%s, StartTime=%v, EndTime=%v, LogPaths=%v" ,
911
900
cardReq .Field , cardReq .StartTime , cardReq .EndTime , cardReq .LogPaths )
0 commit comments