-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize reporting dashboards-plugin configurations and with reporting server settings #222
Merged
zhongnansu
merged 1 commit into
opensearch-project:main
from
zhongnansu:add-plugin-config
Nov 9, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import { | ||
CoreSetup, | ||
Logger, | ||
PluginInitializerContext, | ||
} from '../../../../src/core/server'; | ||
import { ReportingConfigType } from './schema'; | ||
import { get } from 'lodash'; | ||
import { first, map } from 'rxjs/operators'; | ||
import { createConfig$ } from './createConfig'; | ||
|
||
interface Config<BaseType> { | ||
get<Key1 extends keyof BaseType>(key1: Key1): BaseType[Key1]; | ||
get<Key1 extends keyof BaseType, Key2 extends keyof BaseType[Key1]>( | ||
key1: Key1, | ||
key2: Key2 | ||
): BaseType[Key1][Key2]; | ||
} | ||
|
||
interface OsdServerConfigType { | ||
server: { | ||
basePath: string; | ||
host: string; | ||
name: string; | ||
port: number; | ||
protocol: string; | ||
}; | ||
} | ||
|
||
export interface ReportingConfig extends Config<ReportingConfigType> { | ||
osdConfig: Config<OsdServerConfigType>; | ||
} | ||
|
||
export const buildConfig = async ( | ||
initContext: PluginInitializerContext<ReportingConfigType>, | ||
core: CoreSetup, | ||
logger: Logger | ||
): Promise<ReportingConfig> => { | ||
const config$ = initContext.config.create<ReportingConfigType>(); | ||
const serverInfo = core.http.getServerInfo(); | ||
const osdConfig = { | ||
server: { | ||
basePath: core.http.basePath.serverBasePath, | ||
host: serverInfo.hostname, | ||
name: serverInfo.name, | ||
port: serverInfo.port, | ||
protocol: serverInfo.protocol, | ||
}, | ||
}; | ||
|
||
const reportingConfig$ = createConfig$(core, config$, logger); | ||
const reportingConfig = await reportingConfig$.pipe(first()).toPromise(); | ||
return { | ||
get: (...keys: string[]) => get(reportingConfig, keys.join('.'), null), | ||
osdConfig: { | ||
get: (...keys: string[]) => get(osdConfig, keys.join('.'), null), | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { CoreSetup, Logger } from '../../../../src/core/server'; | ||
|
||
import { ReportingConfigType } from './schema'; | ||
|
||
/* | ||
* Set up dynamic config defaults | ||
*/ | ||
export function createConfig$( | ||
core: CoreSetup, | ||
config$: Observable<ReportingConfigType>, | ||
logger: Logger | ||
) { | ||
return config$.pipe( | ||
map((config) => { | ||
const { osd_server: reportingServer } = config; | ||
const serverInfo = core.http.getServerInfo(); | ||
// osd_server.hostname, default to server.host | ||
const osdServerHostname = reportingServer.hostname | ||
? reportingServer.hostname | ||
: serverInfo.hostname; | ||
|
||
// osd_server.port, default to server.port | ||
const osdServerPort = reportingServer.port | ||
? reportingServer.port | ||
: serverInfo.port; | ||
// osd_server.protocol, default to server.protocol | ||
const osdServerProtocol = reportingServer.protocol | ||
? reportingServer.protocol | ||
: serverInfo.protocol; | ||
return { | ||
...config, | ||
osd_server: { | ||
hostname: osdServerHostname, | ||
port: osdServerPort, | ||
protocol: osdServerProtocol, | ||
}, | ||
}; | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import { PluginConfigDescriptor } from '../../../../src/core/server'; | ||
import { ConfigSchema, ReportingConfigType } from './schema'; | ||
export { buildConfig } from './config'; | ||
export { ConfigSchema, ReportingConfigType }; | ||
|
||
export const config: PluginConfigDescriptor<ReportingConfigType> = { | ||
schema: ConfigSchema, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import { schema, TypeOf } from '@osd/config-schema'; | ||
|
||
const OsdServerSchema = schema.object({ | ||
hostname: schema.maybe( | ||
schema.string({ | ||
validate(value) { | ||
if (value === '0') { | ||
return 'must not be "0" for the headless browser to correctly resolve the host'; | ||
} | ||
}, | ||
hostname: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}) | ||
), | ||
port: schema.maybe(schema.number()), | ||
protocol: schema.maybe( | ||
schema.string({ | ||
validate(value) { | ||
if (!/^https?$/.test(value)) { | ||
return 'must be "http" or "https"'; | ||
} | ||
}, | ||
}) | ||
), | ||
}); // default values are all dynamic in createConfig$ | ||
|
||
export const ConfigSchema = schema.object({ | ||
osd_server: OsdServerSchema, | ||
}); | ||
|
||
export type ReportingConfigType = TypeOf<typeof ConfigSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would
0.0.0.0
and127.0.0.1
work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes