Skip to content

Commit 3784993

Browse files
committed
Don't mix snake case and kebab case
1 parent 19fe2d6 commit 3784993

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ from elasticsearch_metrics import metrics
4848

4949

5050
class PageView(metrics.Metric):
51-
user_id = metrics.Integer()
51+
user_id = metrics.Integer(index=True, doc_values=True)
5252
```
5353

5454
Use the `sync_metrics` management command to ensure that the [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html)
@@ -68,7 +68,7 @@ user = User.objects.latest()
6868

6969
# By default we create an index for each day.
7070
# Therefore, this will persist the document
71-
# to an index called, e.g. "myapp_pageview-2020.02.04"
71+
# to an index called, e.g. "myapp_pageview_2020.02.04"
7272
PageView.record(user_id=user.id)
7373
```
7474

@@ -115,7 +115,7 @@ Each `Metric` will have its own [index template](https://www.elastic.co/guide/en
115115
The index template name and glob pattern are computed from the app label
116116
for the containing app and the class's name. For example, a `PageView`
117117
class defined in `myapp/metrics.py` will have an index template with the
118-
name `myapp_pageview` and a template glob pattern of `myapp_pageview-*`.
118+
name `myapp_pageview` and a template glob pattern of `myapp_pageview_*`.
119119

120120
If you declare a `Metric` outside of an app, you will need to set
121121
`app_label`.
@@ -135,7 +135,7 @@ class PageView(metrics.Metric):
135135

136136
class Meta:
137137
template_name = "myapp_pviews"
138-
template = "myapp_pviews-*"
138+
template = "myapp_pviews_*"
139139
```
140140

141141
## Abstract metrics

elasticsearch_metrics/metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __new__(mcls, name, bases, attrs): # noqa: B902
5959
if not template_name:
6060
template_name = "{}_{}".format(app_label, metric_name)
6161
# template is <app label>_<lowercased class name>-*
62-
template = template or "{}_{}-*".format(app_label, metric_name)
62+
template = template or "{}_{}_*".format(app_label, metric_name)
6363

6464
new_cls._template_name = template_name
6565
new_cls._template = template
@@ -115,7 +115,7 @@ class BaseMetric(object):
115115
from elasticsearch_metrics import metrics
116116
117117
class PageView(metrics.Metric):
118-
user_id = metrics.Integer()
118+
user_id = metrics.Integer(index=True, doc_values=True)
119119
120120
class Index:
121121
settings = {
@@ -220,7 +220,7 @@ def get_index_name(cls, date=None):
220220
settings, "ELASTICSEARCH_METRICS_DATE_FORMAT", DEFAULT_DATE_FORMAT
221221
)
222222
date_formatted = date.strftime(dateformat)
223-
return "{}-{}".format(cls._template_name, date_formatted)
223+
return "{}_{}".format(cls._template_name, date_formatted)
224224

225225
@classmethod
226226
def record(cls, timestamp=None, **kwargs):

tests/test_management_commands/test_show_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
def test_without_args(run_mgmt_command):
55
out, err = run_mgmt_command(Command, ["show_metrics"])
66
assert "DummyMetric" in out
7-
assert "dummyapp_dummymetric-*" in out
7+
assert "dummyapp_dummymetric_*" in out

tests/test_metrics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ def test_get_index_name(self):
3636
date = dt.date(2020, 2, 14)
3737
assert (
3838
PreprintView.get_index_name(date=date)
39-
== "osf_metrics_preprintviews-2020.02.14"
39+
== "osf_metrics_preprintviews_2020.02.14"
4040
)
4141

4242
def test_get_index_name_respects_date_format_setting(self, settings):
4343
settings.ELASTICSEARCH_METRICS_DATE_FORMAT = "%Y-%m-%d"
4444
date = dt.date(2020, 2, 14)
4545
assert (
4646
PreprintView.get_index_name(date=date)
47-
== "osf_metrics_preprintviews-2020-02-14"
47+
== "osf_metrics_preprintviews_2020-02-14"
4848
)
4949

5050
def test_get_index_name_gets_index_for_today_by_default(self):
5151
today = timezone.now().date()
5252
today_formatted = today.strftime("%Y.%m.%d")
53-
assert PreprintView.get_index_name() == "osf_metrics_preprintviews-{}".format(
53+
assert PreprintView.get_index_name() == "osf_metrics_preprintviews_{}".format(
5454
today_formatted
5555
)
5656

@@ -102,7 +102,7 @@ def test_get_index_template_default_template_name(self):
102102
template = DummyMetric.get_index_template()
103103
assert isinstance(template, IndexTemplate)
104104
assert template._template_name == "dummyapp_dummymetric"
105-
assert "dummyapp_dummymetric-*" in template.to_dict()["index_patterns"]
105+
assert "dummyapp_dummymetric_*" in template.to_dict()["index_patterns"]
106106

107107
def test_get_index_template_uses_app_label_in_class_meta(self):
108108
class MyMetric(metrics.Metric):
@@ -120,7 +120,7 @@ def test_template_name_defined_with_no_template_falls_back_to_default_template(
120120
assert template._template_name == "dummymetric"
121121
# template is not specified, so it's generated
122122
assert (
123-
"dummyapp_dummymetricwithexplicittemplatename-*"
123+
"dummyapp_dummymetricwithexplicittemplatename_*"
124124
in template.to_dict()["index_patterns"]
125125
)
126126

0 commit comments

Comments
 (0)