You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: provide a default implemention of metric::get_description
Metric classes no longer need to implement `get_description`.
By default, a string with the ID `"metric:{$name}_desc"` is expected to exist in the language file of the defining component.
Our metrics no longer override that method.
Unit tests are simplified.
Documentation reflects the change.
@@ -214,20 +209,24 @@ We want to partition the metric by the block _name_ and therefore return an arra
214
209
The description is what is shown in the admin dashboard.
215
210
It is also what the `monitoringexporter_prometheus` exporter uses to generate its metric `HELP` string.
216
211
217
-
In our example above, we return the [localized string][moodle docs string api] with the ID `metric:blocks_used_help`.
218
-
We just need to actually add the text to be displayed to the plugin's language file.
212
+
By default, a metric is expected to come with a [localized string][moodle docs string api] with the ID `"metric:{$name}_desc"` where `{$name}` is the name of the metric.
213
+
In our example above, there needs to be a string with the ID `metric:blocks_used_desc`.
214
+
So we need to actually add the text to be displayed to the plugin's language file.
219
215
220
216
<details open>
221
217
<summary><code>lang/en/local_example.php</code> (Click to expand/collapse)</summary>
222
218
223
219
```php
224
220
defined('MOODLE_INTERNAL') || die();
225
221
// ...
226
-
$string['metric:blocks_used_help'] = 'Current number of blocks used on the site.';
222
+
$string['metric:blocks_used_desc'] = 'Current number of blocks used on the site.';
227
223
```
228
224
229
225
</details>
230
226
227
+
> [!TIP]
228
+
> You can specify a different string by overriding the `get_description` method in your metric class.
229
+
231
230
#### Registering the metric
232
231
233
232
The new metric class needs to be picked up by the `metric_collection` hook.
@@ -367,10 +366,6 @@ class blocks_used extends metric_with_config {
367
366
return metric_type::GAUGE;
368
367
}
369
368
370
-
public static function get_description(): lang_string {
371
-
return new lang_string('metric:blocks_used_help', 'local_example');
$string['metric:quiz_attempts_in_progress_config:maxdeadlineseconds_help'] = 'Do not count attempts that have a deadline in more than this number of seconds.';
$string['metric:users_online_config:timewindows_help'] = 'Number of seconds since the last user access for that user to be counted as online. Multiple values can be specified, separated by commas; the metric will produce a separate metric value for each time window.';
57
-
$string['metric:users_online_description'] = 'Number of users that have recently accessed the site';
57
+
$string['metric:users_online_desc'] = 'Number of users that have recently accessed the site';
58
58
59
59
$string['monitoring:manage_metrics'] = 'Manage and configure monitoring metrics';
0 commit comments