18
18
import org .elasticsearch .cluster .metadata .ProjectMetadata ;
19
19
import org .elasticsearch .cluster .metadata .Template ;
20
20
import org .elasticsearch .common .compress .CompressedXContent ;
21
+ import org .elasticsearch .common .settings .Setting ;
21
22
import org .elasticsearch .common .settings .Settings ;
22
23
import org .elasticsearch .core .Tuple ;
23
24
import org .elasticsearch .index .IndexMode ;
26
27
import org .elasticsearch .index .IndexVersion ;
27
28
import org .elasticsearch .index .MapperTestUtils ;
28
29
import org .elasticsearch .index .mapper .SourceFieldMapper ;
30
+ import org .elasticsearch .indices .IndicesModule ;
29
31
import org .elasticsearch .license .License ;
30
32
import org .elasticsearch .license .LicenseService ;
31
33
import org .elasticsearch .license .MockLicenseState ;
34
+ import org .elasticsearch .license .XPackLicenseState ;
35
+ import org .elasticsearch .license .internal .XPackLicenseStatus ;
32
36
import org .elasticsearch .test .ESTestCase ;
33
37
import org .elasticsearch .xpack .logsdb .patterntext .PatternTextFieldMapper ;
34
38
import org .junit .Before ;
@@ -72,6 +76,7 @@ public class LogsdbIndexModeSettingsProviderTests extends ESTestCase {
72
76
""" ;
73
77
74
78
private LogsdbLicenseService logsdbLicenseService ;
79
+ private LogsdbLicenseService basicLogsdbLicenseService ;
75
80
private final AtomicInteger newMapperServiceCounter = new AtomicInteger ();
76
81
77
82
@ Before
@@ -84,6 +89,13 @@ public void setup() throws Exception {
84
89
logsdbLicenseService = new LogsdbLicenseService (Settings .EMPTY );
85
90
logsdbLicenseService .setLicenseState (licenseState );
86
91
logsdbLicenseService .setLicenseService (mockLicenseService );
92
+
93
+ var basicLicenseState = new XPackLicenseState (() -> 0L , new XPackLicenseStatus (License .OperationMode .BASIC , true , null ));
94
+ var basicLicenseService = mock (LicenseService .class );
95
+ when (basicLicenseService .getLicense ()).thenReturn (null );
96
+ basicLogsdbLicenseService = new LogsdbLicenseService (Settings .EMPTY );
97
+ basicLogsdbLicenseService .setLicenseState (basicLicenseState );
98
+ basicLogsdbLicenseService .setLicenseService (basicLicenseService );
87
99
}
88
100
89
101
private LogsdbIndexModeSettingsProvider withSyntheticSourceDemotionSupport (boolean enabled ) {
@@ -121,13 +133,23 @@ private Settings generateLogsdbSettings(Settings settings, String mapping) throw
121
133
}
122
134
123
135
private Settings generateLogsdbSettings (Settings settings , String mapping , Version version ) throws IOException {
124
- var provider = new LogsdbIndexModeSettingsProvider (
125
- logsdbLicenseService ,
126
- Settings .builder ().put ("cluster.logsdb.enabled" , true ).build ()
127
- );
136
+ return generateLogsdbSettings (settings , mapping , version , logsdbLicenseService );
137
+ }
138
+
139
+ private Settings generateLogsdbSettings (Settings settings , String mapping , Version version , LogsdbLicenseService licenseService )
140
+ throws IOException {
141
+ var provider = new LogsdbIndexModeSettingsProvider (licenseService , Settings .builder ().put ("cluster.logsdb.enabled" , true ).build ());
142
+ var logsdbPlugin = new LogsDBPlugin (settings );
128
143
provider .init (im -> {
129
144
newMapperServiceCounter .incrementAndGet ();
130
- return MapperTestUtils .newMapperService (xContentRegistry (), createTempDir (), im .getSettings (), im .getIndex ().getName ());
145
+ return MapperTestUtils .newMapperService (
146
+ xContentRegistry (),
147
+ createTempDir (),
148
+ im .getSettings (),
149
+ new IndicesModule (List .of (logsdbPlugin )),
150
+ im .getIndex ().getName (),
151
+ logsdbPlugin .getSettings ().stream ().filter (Setting ::hasIndexScope ).toArray (Setting <?>[]::new )
152
+ );
131
153
}, IndexVersion ::current , () -> version , true , true );
132
154
Settings .Builder settingsBuilder = builder ();
133
155
provider .provideAdditionalSettings (
@@ -959,19 +981,34 @@ public void testExplicitRoutingPathNotAllowedByLicense() throws Exception {
959
981
assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), empty ());
960
982
}
961
983
962
- public void testPatternTextNotAllowedByLicense () throws Exception {
963
- MockLicenseState licenseState = MockLicenseState . createMock ();
964
- when ( licenseState . copyCurrentLicenseState ()). thenReturn ( licenseState );
965
- when ( licenseState . isAllowed ( same ( LogsdbLicenseService . PATTERN_TEXT_TEMPLATING_FEATURE ))). thenReturn ( false );
966
- logsdbLicenseService = new LogsdbLicenseService ( Settings . EMPTY );
967
- logsdbLicenseService . setLicenseState ( licenseState ) ;
984
+ public void testPatternTextNotAllowedByLicense () throws IOException {
985
+ String [] patternTextLicenceCheckedFieldMappings = {
986
+ "{ \" _doc \" :{ \" properties \" :{ \" message \" :{ \" type \" : \" pattern_text \" }}}}" ,
987
+ "{ \" _doc \" :{ \" properties \" :{ \" error \" :{ \" properties \" :{ \" message \" :{ \" type \" : \" pattern_text \" }}}}}}" ,
988
+ "{ \" _doc \" :{ \" properties \" :{ \" foo \" :{ \" type \" : \" pattern_text \" }}}}" ,
989
+ "{ \" _doc \" :{ \" properties \" :{ \" bar \" :{ \" properties \" :{ \" baz \" :{ \" type \" : \" pattern_text \" }}}}}}" } ;
968
990
969
- var settings = Settings .builder ()
970
- .put (IndexSortConfig .INDEX_SORT_FIELD_SETTING .getKey (), "host,message" )
971
- .put (IndexSettings .LOGSDB_ROUTE_ON_SORT_FIELDS .getKey (), true )
991
+ var expectedSettings = Settings .builder ()
992
+ .put (IndexSettings .LOGSDB_ADD_HOST_NAME_FIELD .getKey (), true )
993
+ .put (IndexSettings .LOGSDB_SORT_ON_HOST_NAME .getKey (), true )
994
+ .put (PatternTextFieldMapper .DISABLE_TEMPLATING_SETTING .getKey (), true )
972
995
.build ();
973
- Settings result = generateLogsdbSettings (settings );
974
- assertTrue (PatternTextFieldMapper .DISABLE_TEMPLATING_SETTING .get (result ));
996
+
997
+ for (String mapping : patternTextLicenceCheckedFieldMappings ) {
998
+ var result = generateLogsdbSettings (Settings .EMPTY , mapping , Version .CURRENT , basicLogsdbLicenseService );
999
+ assertEquals (expectedSettings , result );
1000
+ }
1001
+ }
1002
+
1003
+ public void testPatternTextNotAllowedByLicenseAlreadyDisallowed () throws IOException {
1004
+ Settings settings = Settings .builder ().put (PatternTextFieldMapper .DISABLE_TEMPLATING_SETTING .getKey (), "true" ).build ();
1005
+ var result = generateLogsdbSettings (settings , null , Version .CURRENT , basicLogsdbLicenseService );
1006
+ var expected = Settings .builder ()
1007
+ .put (IndexSettings .LOGSDB_ADD_HOST_NAME_FIELD .getKey (), true )
1008
+ .put (IndexSettings .LOGSDB_SORT_ON_HOST_NAME .getKey (), true )
1009
+ .put (PatternTextFieldMapper .DISABLE_TEMPLATING_SETTING .getKey (), true )
1010
+ .build ();
1011
+ assertEquals (expected , result );
975
1012
}
976
1013
977
1014
public void testSortAndHostNamePropagateValue () throws Exception {
0 commit comments