14 Jun 2024
03:44 PM
- last edited on
17 Jun 2024
07:41 AM
by
MaciejNeumann
Hi!
We have auto tags for "sql:sql_server_availability_replica" for our SQL Servers, but since the extension upgraded to 2.3.0, it doesn't work anymore. I know in the patch notes it says the relation changed for the entity selector, so I updated our query, but it still doesn't work.
Here's the old query before v2.3.0:
type("sql:sql_server_availability_replica"),toRelationships.runsOn(type("sql:sql_server_availability_database"),fromRelationships.isInstanceOf(type("sql:sql_server_database"),fromRelationships.isChildOf(type("sql:sql_server_instance"),fromRelationships.runsOn(type("sql:sql_server_host"),fromRelationships.isSameAs(type("HOST"),fromRelationships.isInstanceOf(type("HOST_GROUP"),detectedName("xxxxxxxxxx")))))))
Here's the updated query after v2.3.0:
type("sql:sql_server_availability_replica"),fromRelationships.runsOn(type("sql:sql_server_instance"),fromRelationships.runsOn(type("sql:sql_server_host"),fromRelationships.isSameAs(type("HOST"),fromRelationships.isInstanceOf(type("HOST_GROUP"),detectedName("xxxxxxxxxx")))))
Any help would be appreciated, thanks!
Solved! Go to Solution.
18 Jun 2024 03:18 PM
If we the expression and compare it with relationship definitions from `extension.yaml` downloadable from the Hub we can verify it step by step:
# Get all Availability Replica entities...
type("sql:sql_server_availability_replica"),
# ...which have a toType "RUNS_ON" relationship to Instance entities.
fromRelationships.runsOn(
# Filter down to only those Instances...
type("sql:sql_server_instance"),
# ...that have a toType "RUNS_ON" relationship to SQL Host entitites.
fromRelationships.runsOn(
# Filter down to only those SQL Hosts...
type("sql:sql_server_host"),
# ...that have a toType "SAME_AS" relationship to actual HOSTs.
fromRelationships.isSameAs(
# And finally, only consider HOSTs that are part of the HOST_GROUP...
type("HOST"),
fromRelationships.isInstanceOf(
type("HOST_GROUP"),
# ...with a specific name.
detectedName("xxxxxxxxxx")
)
)
)
)
Relationship between Availability Replica to Instance:
typeOfRelation: RUNS_ON
fromType: sql:sql_server_availability_replica
toType: sql:sql_server_instance
enabled: true
sources:
- sourceType: Metrics
condition: $prefix(sql-server)Relationship between Instance and SQL Host:
typeOfRelation: RUNS_ON
fromType: sql:sql_server_instance
toType: sql:sql_server_host
enabled: true
sources:
- sourceType: Metrics
condition: $prefix(sql-server)Relationship between SQL Host and HOST:
typeOfRelation: SAME_AS
fromType: sql:sql_server_host
toType: host
enabled: true
sources:
- sourceType: Entities
mappingRules:
- sourceProperty: dt.ip_addresses
sourceTransformation: To lower case
destinationProperty: ipAddress
destinationTransformation: To lower case
Based on the above, the expression of entity selector is correct! The only place I can see it breaking down is in the relationship between the SQL Host and HOST, where it compares the detected IP Addresses of both.
The IP Address of the SQL Server Instance we connect to must match one of the IP Addresses detected on the HOST by OneAgent. But this somehow worked in previous version.
If nothing, I recommend opening a support ticket.
21 Oct 2025 07:26 AM
I also used that pattern, but based on metadata. Also, in the answer from vagiz_duseev, the availability databases are missing. So here are all my tagging rules for SQL:
SQL host:
type("sql:sql_server_host"),fromRelationships.isSameAs(type("HOST"),tag([Environment]Application:NAME))
SQL instance:
type("sql:sql_server_instance"),fromRelationships.runsOn(type("sql:sql_server_host"),fromRelationships.isSameAs(type("HOST"),tag([Environment]Application:NAME)))
SQL server database:
type(sql:sql_server_database),fromRelationships.isChildOf(type(sql:sql_server_instance),fromRelationships.runsOn(type("sql:sql_server_host"),fromRelationships.isSameAs(type(HOST),tag([Environment]Application:NAME))))
SQL server availability replica:
type("sql:sql_server_availability_replica"),fromRelationships.isSameAs(type(sql:sql_server_instance),fromRelationships.runsOn(type("sql:sql_server_host"),fromRelationships.isSameAs(type("HOST"),tag([Environment]Application:NAME))))
SQL server availability group:
type(sql:sql_server_availability_group),toRelationships.isInstanceOf(type(sql:sql_server_availability_replica),fromRelationships.isSameAs(type(sql:sql_server_instance),fromRelationships.runsOn(type("sql:sql_server_host"),fromRelationships.isSameAs(type("HOST"),tag([Environment]Application:NAME)))))
SQL server availability database:
type(sql:sql_server_availability_database),fromRelationships.runsOn(type(sql:sql_server_availability_replica),,fromRelationships.isSameAs(type(sql:sql_server_instance),fromRelationships.runsOn(type("sql:sql_server_host"),fromRelationships.isSameAs(type("HOST"),tag([Environment]Application:NAME)))))
03 Nov 2025 06:39 PM
I've tried your tagging rules and the ones related with SQL host, SQL instance and SQL server database worked, but the ones related with SQL server availability replica, SQL server availability group and SQL server availability database didn't return any data.
04 Nov 2025 07:45 AM
Hi,
Topology can be different depending of SQL extension version. Maybe it was updated in a release. I would recommend checking topology relationships in your environment:
Best regards
04 Nov 2025 08:32 AM
I've reviewed the settings and topology of my SQL Extension:
type("sql:sql_server_availability_replica"),fromRelationships.isSameAs(type(sql:sql_server_instance),fromRelationships.runsOn(type("sql:sql_server_host"),fromRelationships.isSameAs(type("HOST"),tag([Environment]Application:NAME))))
should work, but I don't get any entity.
05 Nov 2025 12:31 PM
Hi Damian,
I just checked it and we do indeed get the proper data from the relationship-based entity selector. I would recommend to check the relationships for your replicas via the API. You can open up the replica you're looking at, copy the custom_device ID and use it in the monitored entities API with the GET /entities/{entityId} API to see the relationships that are present in your environment.
05 Nov 2025 01:35 PM
Hi,
I would recommend create a metric selector per SQL entity:
Issue is you cannot use placeholder, it means, you need to create a custom metric selector adding tag value.
This product idea would be helpful to avoid creating rules per tag.
Best regards