Skip to content

Commit

Permalink
Optimize replication information retrieval scope for improved perform…
Browse files Browse the repository at this point in the history
…ance

Modified the scope of replication information retrieval.
Previously, sub scope was used, which fetched all entries under the base DN.
Changed it to base to retrieve information only from the base DN itself.
This change improves performance by limiting the scope of the query.
  • Loading branch information
wadahiro committed Dec 27, 2024
1 parent 5983705 commit 44fa26e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const (

type query struct {
baseDN string
scope int
searchFilter string
searchAttr string
metric *prometheus.GaugeVec
Expand Down Expand Up @@ -277,26 +278,30 @@ var (
queries = []*query{
{
baseDN: baseDN,
scope: ldap.ScopeWholeSubtree,
searchFilter: objectClass(monitoredObject),
searchAttr: monitoredInfo,
metric: monitoredObjectGauge,
setData: setValue,
}, {
baseDN: baseDN,
scope: ldap.ScopeWholeSubtree,
searchFilter: objectClass(monitorCounterObject),
searchAttr: monitorCounter,
metric: monitorCounterObjectGauge,
setData: setValue,
},
{
baseDN: opsBaseDN,
scope: ldap.ScopeWholeSubtree,
searchFilter: objectClass(monitorOperation),
searchAttr: monitorOpCompleted,
metric: monitorOperationGauge,
setData: setValue,
},
{
baseDN: opsBaseDN,
scope: ldap.ScopeWholeSubtree,
searchFilter: objectClass(monitorOperation),
searchAttr: monitorOpCompleted,
metric: monitorOperationGauge,
Expand Down Expand Up @@ -376,6 +381,7 @@ func (s *Scraper) addReplicationQueries() {
queries = append(queries,
&query{
baseDN: s.Sync,
scope: ldap.ScopeBaseObject,
searchFilter: "(contextCSN=*)",
searchAttr: monitorReplicationFilter,
metric: monitorReplicationGauge,
Expand Down Expand Up @@ -498,7 +504,7 @@ func (s *Scraper) scrapeReplication() []ReplicaStatus {
}

req := ldap.NewSearchRequest(
s.Sync, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
s.Sync, ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false,
"(contextCSN=*)", []string{monitorReplicationFilter}, nil,
)
sr, err := replica.Search(req)
Expand Down Expand Up @@ -549,7 +555,7 @@ func (s *Scraper) scrapeReplication() []ReplicaStatus {

func scrapeQuery(conn *ldap.Conn, q *query) error {
req := ldap.NewSearchRequest(
q.baseDN, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
q.baseDN, q.scope, ldap.NeverDerefAliases, 0, 0, false,
q.searchFilter, []string{q.searchAttr}, nil,
)
sr, err := conn.Search(req)
Expand Down

0 comments on commit 44fa26e

Please sign in to comment.