2016-04-22 35 views
0

我在Windows上運行帶有MSSQL後端的SonarQube 5.3。SonarQube使用不正確的(?)ElasticSearch查詢來獲取ScmAccountToUser

當創建新問題時,SonarQube查詢其ElasticSearch用戶索引,以獲取呈現該問題的行的「git blame」信息的作者登錄。

下面在/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueAssigner.java發生:

=>的 「GIT中怪」 信息返回作者受影響的線路,在我的示例的(匿名):

steve [email protected] 

=>此值在ScmAccountToUser,其懶惰地查詢ElasticSearch指數「用戶」擡頭。我添加了一些調試輸出來打印ES查詢,它是:

{ 
    "size": 3, 
    "query": { 
    "filtered": { 
     "query": { 
     "match_all": {} 
     }, 
     "filter": { 
     "bool": { 
      "must": { 
      "term": { 
       "active": true 
      } 
      }, 
      "should": [ 
      { 
       "term": { 
       "login": "steve [email protected]" 
       } 
      }, 
      { 
       "term": { 
       "email": "steve [email protected]" 
       } 
      }, 
      { 
       "term": { 
       "scmAccounts": "steve [email protected]" 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

此查詢返回0個結果。

相反,當我列舉整個索引,我得到一擊一般應該匹配該用戶:

{ - 
    "took": 4, 
    "timed_out": false, 
    "_shards": { - 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { - 
    "total": 39, 
    "max_score": 1, 
    "hits": [ - 
     { - 
     // snip 
     }, 
     // snip 
     { - 
     "_index": "users", 
     "_type": "user", 
     "_id": "steve.smith", 
     "_score": 1, 
     "_source": { - 
      "createdAt": 1442988141642, 
      "name": "Steve Smith", 
      "active": true, 
      "login": "steve.smith", 
      "scmAccounts": [ - 
      " 
", 
      "steve [email protected] 
", 
      "[email protected] 
" 
      ], 
      "email": "[email protected]", 
      "updatedAt": 1450088380632 
     } 
     }, 
     // snip 
    ] 
    } 
} 

這個問題目前阻止我SonarQube例如從自動分配一個很大的問題。我正在確定何時/如何中斷,因爲某些自動分配功能先前已成功。

這是查詢中還是數據中的錯誤?我能以某種方式解決這個問題嗎?

+0

scmAccounts字段的映射是什麼?如果它不是'not_analyzed'字符串字段,那就是原因。 – Val

+0

映射做具體說明: // ... 「scmAccounts」:{ - 「索引」: 「not_analyzed」, 「類型」: 「串」 }, // ... 而不同來自其他領域,例如登錄: 「登錄」:{ - 「索引」: 「not_analyzed」, 「類型」: 「串」, 「字段」:{ - 「n元語法」:{ - 「search_analyzer」: 「search_ngrams」 , 「index_analyzer」: 「index_ngrams」, 「類型」: 「串」 }} } , 這是映射的配置錯誤呢?我已經完全恢復了索引,所以問題不斷出現。 – ThePadawan

+1

根本原因似乎是scm賬戶中的空白。你確認嗎? –

回答

2

事實證明,問題是由於「scmAccounts」字段條目中的換行符引起的。

通過手動重新添加SCM賬戶在SonarQube UI,這些領域進行了更新,以

"scmAccounts": 
[ - 
      "steve [email protected]", 
      "[email protected]" 
], 

,之後查詢成功,問題分配成功了。

換行符首先進入了字段,因爲我手動從SQL備份SQL INSERT腳本中恢復了SQL服務器上的「用戶」表。

+1

很高興知道。誰引入了換行符?你還是SQLServer備份工具?在後一種情況下,SonarQube應該覆蓋這個角落案例並在索引到Elasticsearch時清理SCM帳戶。 –

+0

@ SimonBrandhof-SonarSource我執行了一個將數據庫導出到.sql INSERT腳本(使用MSSQL Server 2012)的導出換行符的表格式導出。可能有一個問題,因爲窗口行結束 - 我可以發送一個users.sql(審查)文件來重現此問題。請聯繫。 – ThePadawan

+0

謝謝,但它很容易重現。由於問題在於數據庫備份,因此SonarQube中無需修復任何內容。 –